godprotocol 1.0.839 → 1.0.841

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,143 +1,139 @@
1
- import { _id } from "generalised-datastore/utils/functions";
2
- import framer from "../framer";
3
- import opcodes from "../opcodes";
4
- import Account from "./Account";
5
- import Blockweb from "./Blockweb";
6
- import Oracle from "./Oracle";
7
-
8
- class Manager {
9
- constructor(meta) {
10
- meta = meta || {};
11
-
12
- this.compression = meta.compression;
13
- this.manager_id = _id("manager");
14
- this.accounts = new Object();
15
- this.running = 0;
16
- this.tracks = new Object();
17
- this.web = new Blockweb(this);
18
- this.oracle = new Oracle(this, { compression: this.compression });
19
- this.servers = new Array();
20
- }
21
-
22
- stringify = (str) => {
23
- let obj = {
24
- _id: this.manager_id,
25
- servers: this.servers,
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _functions = require("generalised-datastore/utils/functions");
8
+ var _framer = _interopRequireDefault(require("../framer"));
9
+ var _opcodes = _interopRequireDefault(require("../opcodes"));
10
+ var _Account = _interopRequireDefault(require("./Account"));
11
+ var _Blockweb = _interopRequireDefault(require("./Blockweb"));
12
+ var _Oracle = _interopRequireDefault(require("./Oracle"));
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
18
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
19
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
20
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
22
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ var Manager = /*#__PURE__*/_createClass(function Manager(_meta) {
24
+ var _this = this;
25
+ _classCallCheck(this, Manager);
26
+ _defineProperty(this, "stringify", function (str) {
27
+ var obj = {
28
+ _id: _this.manager_id,
29
+ servers: _this.servers
26
30
  };
27
-
28
31
  return str ? JSON.stringify(obj) : obj;
29
- };
30
-
31
- initiate = (meta) => {
32
- this.initiator = this.add_account(
33
- process.env.INITIATOR || "initiator",
34
- meta
35
- );
36
-
37
- return this.initiator;
38
- };
39
-
40
- start_clock = () => {
41
- let frequency = Number(process.env.HERTS) || 10;
42
- this.clock = setInterval(() => {
43
- for (let account in this.tracks) {
44
- let track = this.tracks[account];
45
- let program = track.slice(-1)[0];
46
-
32
+ });
33
+ _defineProperty(this, "initiate", function (meta) {
34
+ _this.initiator = _this.add_account(process.env.INITIATOR || "initiator", meta);
35
+ return _this.initiator;
36
+ });
37
+ _defineProperty(this, "start_clock", function () {
38
+ var frequency = Number(process.env.HERTS) || 10;
39
+ _this.clock = setInterval(function () {
40
+ for (var account in _this.tracks) {
41
+ var track = _this.tracks[account];
42
+ var program = track.slice(-1)[0];
47
43
  if (program.hold) continue;
48
-
49
- let instruction = program.sequence[program.pointer];
50
-
44
+ var instruction = program.sequence[program.pointer];
51
45
  program.account.vm.execute(instruction, program);
52
46
  program.pointer++;
53
-
54
47
  if (program.pointer === program.sequence.length) {
55
48
  program.account.flush_buffer(program.pid);
56
-
57
49
  track.pop();
58
50
  }
59
51
  if (!track.length) {
60
- this.running -= 1;
61
- delete this.tracks[account];
52
+ _this.running -= 1;
53
+ delete _this.tracks[account];
62
54
  program.account.chain.mine(program.account.vm);
63
55
  }
64
56
  }
65
-
66
- !this.running && clearInterval(this.clock);
57
+ !_this.running && clearInterval(_this.clock);
67
58
  }, frequency);
68
- };
69
-
70
- get_account = (name) => this.accounts[name];
71
-
72
- add_account = (name, meta) => {
59
+ });
60
+ _defineProperty(this, "get_account", function (name) {
61
+ return _this.accounts[name];
62
+ });
63
+ _defineProperty(this, "add_account", function (name, meta) {
73
64
  meta = meta || {};
74
65
  if (!name) name = meta.name;
75
-
76
- let account;
66
+ var account;
77
67
  if (!name) {
78
- account = { error: true, error_message: "Name cannot be blank" };
68
+ account = {
69
+ error: true,
70
+ error_message: "Name cannot be blank"
71
+ };
79
72
  } else {
80
- account = this.get_account(name);
81
-
73
+ account = _this.get_account(name);
82
74
  if (!account) {
83
- account = new Account(name, { ...meta, manager: this });
84
-
85
- opcodes(account);
86
- framer(account, meta.on_framed);
87
-
88
- this.accounts[account.name] = account;
75
+ account = new _Account["default"](name, _objectSpread(_objectSpread({}, meta), {}, {
76
+ manager: _this
77
+ }));
78
+ (0, _opcodes["default"])(account);
79
+ (0, _framer["default"])(account, meta.on_framed);
80
+ _this.accounts[account.name] = account;
89
81
  if (meta.string) account = account.stringify();
90
- } else if (meta && meta.private && !account.private) {
91
- account.private = true;
82
+ } else if (meta && meta["private"] && !account["private"]) {
83
+ account["private"] = true;
92
84
  }
93
85
  }
94
-
95
86
  return meta.string ? JSON.stringify(account) : account;
96
- };
97
-
98
- push = (program) => {
99
- let track = this.tracks[program.account.name];
100
-
87
+ });
88
+ _defineProperty(this, "push", function (program) {
89
+ var track = _this.tracks[program.account.name];
101
90
  if (track) {
102
- track.push({ ...program, pointer: 0 });
91
+ track.push(_objectSpread(_objectSpread({}, program), {}, {
92
+ pointer: 0
93
+ }));
103
94
  } else {
104
- track = [{ ...program, pointer: 0 }];
105
- this.tracks[program.account.name] = track;
106
-
107
- this.running++;
108
- this.running === 1 && this.start_clock();
95
+ track = [_objectSpread(_objectSpread({}, program), {}, {
96
+ pointer: 0
97
+ })];
98
+ _this.tracks[program.account.name] = track;
99
+ _this.running++;
100
+ _this.running === 1 && _this.start_clock();
109
101
  }
110
- };
111
-
112
- get_initiator = () => this.initiator || this.initiate();
113
-
114
- endpoint = (endpoint, payload, callback) => {
115
- let account = this.get_account(payload.account);
102
+ });
103
+ _defineProperty(this, "get_initiator", function () {
104
+ return _this.initiator || _this.initiate();
105
+ });
106
+ _defineProperty(this, "endpoint", function (endpoint, payload, callback) {
107
+ var account = _this.get_account(payload.account);
116
108
  if (!account) {
117
- return this.get_initiator().run_callback(callback, {
109
+ return _this.get_initiator().run_callback(callback, {
118
110
  error: true,
119
111
  error_message: "Account is not found",
120
- payload,
121
- endpoint,
112
+ payload: payload,
113
+ endpoint: endpoint
122
114
  });
123
115
  }
124
-
125
- if (
126
- !account.validate(
127
- payload.program || payload.payload,
128
- payload.signature,
129
- callback || payload.callback
130
- )
131
- )
132
- return;
133
-
134
- let method = account[endpoint];
135
- typeof method === "function" && method({ ...payload, callback });
136
- };
137
-
138
- add_server = (server) => {
139
- this.servers.push(server);
140
- };
141
- }
142
-
143
- export default Manager;
116
+ if (!account.validate(payload.program || payload.payload, payload.signature, callback || payload.callback)) return;
117
+ var method = account[endpoint];
118
+ typeof method === "function" && method(_objectSpread(_objectSpread({}, payload), {}, {
119
+ callback: callback
120
+ }));
121
+ });
122
+ _defineProperty(this, "add_server", function (server) {
123
+ _this.servers.push(server);
124
+ });
125
+ _meta = _meta || {};
126
+ this.compression = _meta.compression;
127
+ this.manager_id = (0, _functions._id)("manager");
128
+ this.accounts = new Object();
129
+ this.running = 0;
130
+ this.tracks = new Object();
131
+ this.web = new _Blockweb["default"](this);
132
+ this.oracle = new _Oracle["default"](this, {
133
+ compression: this.compression,
134
+ datastore: _meta.datastore
135
+ });
136
+ this.servers = new Array();
137
+ });
138
+ var _default = Manager;
139
+ exports["default"] = _default;
@@ -1,49 +1,49 @@
1
- import { obj } from "../framer";
2
-
3
- class Opcodes {
4
- constructor() {
5
- this.opcodes = new Object();
6
- }
7
-
8
- set = (opcode, circuit) => {
9
- this.opcodes[opcode] = circuit;
10
- obj.Opcodes[opcode] = null;
11
-
12
- this.account.assembler.opcodes.push(opcode);
13
- };
14
-
15
- prepare_operation = (opcode, context) => {
16
- let circ = this.opcodes[opcode];
17
-
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _framer = require("../framer");
8
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
10
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
11
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ var Opcodes = /*#__PURE__*/_createClass(function Opcodes() {
16
+ var _this = this;
17
+ _classCallCheck(this, Opcodes);
18
+ _defineProperty(this, "set", function (opcode, circuit) {
19
+ _this.opcodes[opcode] = circuit;
20
+ _framer.obj.Opcodes[opcode] = null;
21
+ _this.account.assembler.opcodes.push(opcode);
22
+ });
23
+ _defineProperty(this, "prepare_operation", function (opcode, context) {
24
+ var circ = _this.opcodes[opcode];
18
25
  if (typeof circ !== "function") return;
19
-
20
- let buf = context.get_buffer();
21
-
22
- let args =
23
- context.account.read(buf && buf.inputs) ||
24
- this.account.stdin.splice(-1)[0];
25
-
26
- let res = circ(args, this);
27
-
28
- this.stdin(res);
29
- };
30
-
31
- stdin = (object, cb) => {
26
+ var buf = context.get_buffer();
27
+ var args = context.account.read(buf && buf.inputs) || _this.account.stdin.splice(-1)[0];
28
+ var res = circ(args, _this);
29
+ _this.stdin(res);
30
+ });
31
+ _defineProperty(this, "stdin", function (object, cb) {
32
32
  if (object == null) {
33
- this.flags.void = true;
33
+ _this.flags["void"] = true;
34
34
  return;
35
35
  }
36
- this.flags.void = false;
37
-
38
- this.flags.zero = !object;
39
- if (typeof object === "number") this.flags.neg = object < 0;
40
-
41
- let code_string =
42
- typeof object !== "string" ? JSON.stringify(object) : object;
43
-
44
- this.account.assembler.run(code_string, { cb, pure: true });
36
+ _this.flags["void"] = false;
37
+ _this.flags.zero = !object;
38
+ if (typeof object === "number") _this.flags.neg = object < 0;
39
+ var code_string = typeof object !== "string" ? JSON.stringify(object) : object;
40
+ _this.account.assembler.run(code_string, {
41
+ cb: cb,
42
+ pure: true
43
+ });
45
44
  // console.log(`Writing in: ${code_string}`);
46
- };
47
- }
48
-
49
- export default Opcodes;
45
+ });
46
+ this.opcodes = new Object();
47
+ });
48
+ var _default = Opcodes;
49
+ exports["default"] = _default;
package/Objects/Oracle.js CHANGED
@@ -1,104 +1,144 @@
1
- import fs from "fs";
2
- import GDS from "generalised-datastore";
3
- import { hash } from "../utils/hash";
4
-
5
- class Oracle {
6
- constructor(mgr, meta) {
7
- meta = meta || {};
8
-
9
- this.compression = meta.compression;
10
- this.fs = fs;
11
- this.mgr = mgr;
12
- this.datapaths = new Object();
13
- this.gds = new GDS(process.env.DATASTORE || "godprotocol").sync({
14
- manager: this.mgr,
15
- });
16
- }
17
-
18
- get_folder = (physical_address, options) => {
19
- if (typeof options !== "object") {
20
- options = { no_new: options ? false : true };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _generalisedDatastore = _interopRequireDefault(require("generalised-datastore"));
9
+ var _hash = require("../utils/hash");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
12
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
13
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
14
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
15
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
16
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
17
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
18
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
19
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
20
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
+ var Oracle = /*#__PURE__*/_createClass(function Oracle(mgr, meta) {
22
+ var _this = this;
23
+ _classCallCheck(this, Oracle);
24
+ _defineProperty(this, "get_folder", function (physical_address, options) {
25
+ if (_typeof(options) !== "object") {
26
+ options = {
27
+ no_new: options ? false : true
28
+ };
21
29
  }
22
- return this.gds.folder(this.hash(physical_address));
23
- };
24
-
25
- set = (path, { type, obj }) => {
26
- this.datapaths[path] = {
27
- obj,
28
- type,
30
+ return _this.gds.folder(_this.hash(physical_address));
31
+ });
32
+ _defineProperty(this, "set", function (path, _ref) {
33
+ var type = _ref.type,
34
+ obj = _ref.obj;
35
+ _this.datapaths[path] = {
36
+ obj: obj,
37
+ type: type
29
38
  };
30
- };
31
-
32
- get = (path) => {
33
- let obj = this.datapaths[path];
34
-
39
+ });
40
+ _defineProperty(this, "get", function (path) {
41
+ var obj = _this.datapaths[path];
35
42
  if (!obj) {
36
43
  try {
37
- obj = this.fs.readFileSync(path);
38
- obj = JSON.parse(obj).data;
39
- let type = obj && obj.data && typeof obj.data;
40
- type =
41
- type === "object" ? (Array.isArray(obj) ? "array" : "twain") : type;
42
-
43
- obj = { type, obj };
44
- this.set(path, obj);
44
+ obj = _this.fs.readFileSync("".concat(_this.mgr.initiator.root, "/").concat(path));
45
+ obj = JSON.parse(obj).payload;
46
+ var type = obj && obj.payload && _typeof(obj.payload);
47
+ type = type === "object" ? Array.isArray(obj) ? "array" : "twain" : type;
48
+ obj = {
49
+ type: type,
50
+ obj: obj
51
+ };
52
+ _this.set(path, obj);
45
53
  } catch (e) {}
46
54
  }
47
-
48
55
  return obj;
49
- };
50
-
51
- hash = (data) => {
56
+ });
57
+ _defineProperty(this, "hash", function (data) {
52
58
  data = typeof data !== "string" ? JSON.stringify(data) : data;
53
- return hash(data);
54
- };
55
-
56
- handle_compression = ({ addr, data, no_string }) => {
57
- if (this.compression) {
58
- let res = this.compression({ addr, data, no_string });
59
+ return (0, _hash.hash)(data);
60
+ });
61
+ _defineProperty(this, "handle_compression", function (_ref2) {
62
+ var addr = _ref2.addr,
63
+ data = _ref2.data,
64
+ no_string = _ref2.no_string;
65
+ if (_this.compression) {
66
+ var res = _this.compression({
67
+ addr: addr,
68
+ data: data,
69
+ no_string: no_string
70
+ });
59
71
  if (res) data = res.data;
60
72
  }
61
- if (!no_string && (typeof addr !== "string" || typeof data !== "string"))
62
- return;
63
-
73
+ if (!no_string && (typeof addr !== "string" || typeof data !== "string")) return;
64
74
  return data;
65
- };
66
-
67
- write = (address, payload) => {
68
- payload = JSON.stringify({ payload });
69
- let data = this.handle_compression({
75
+ });
76
+ _defineProperty(this, "write", function (address, payload) {
77
+ payload = JSON.stringify({
78
+ payload: payload
79
+ });
80
+ var data = _this.handle_compression({
70
81
  addr: address,
71
- data: payload,
82
+ data: payload
72
83
  });
73
-
74
- this.fs.writeFileSync(address, data, { encoding: "utf-8" });
75
- };
76
-
77
- fetch = async (payload, callback) => {
78
- let { physical_address, config, remote, query } = payload,
79
- result;
80
-
81
- let folder = this.get_folder(physical_address);
82
-
83
- if (config) {
84
- result = folder.config.stringify();
85
- folder.add_remote(remote);
86
- } else {
87
- if (!folder.check_remote(query.operation)) {
88
- result = {
89
- error: true,
90
- error_message: "Query operation cannot be performed remotely.",
91
- };
92
- } else {
93
- let op = folder[query.operation];
94
-
95
- result = await op(query.query, query.options);
96
- folder.remote_stuff(remote, result);
97
- }
98
- }
99
-
100
- callback(result);
101
- };
102
- }
103
-
104
- export default Oracle;
84
+ _this.fs.writeFileSync("".concat(_this.mgr.initiator.root, "/").concat(address), data, {
85
+ encoding: "utf-8"
86
+ });
87
+ });
88
+ _defineProperty(this, "fetch", /*#__PURE__*/function () {
89
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload, callback) {
90
+ var physical_address, config, remote, query, result, folder, op;
91
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
92
+ while (1) switch (_context.prev = _context.next) {
93
+ case 0:
94
+ physical_address = payload.physical_address, config = payload.config, remote = payload.remote, query = payload.query;
95
+ folder = _this.get_folder(physical_address);
96
+ if (!config) {
97
+ _context.next = 7;
98
+ break;
99
+ }
100
+ result = folder.config.stringify();
101
+ folder.add_remote(remote);
102
+ _context.next = 16;
103
+ break;
104
+ case 7:
105
+ if (folder.check_remote(query.operation)) {
106
+ _context.next = 11;
107
+ break;
108
+ }
109
+ result = {
110
+ error: true,
111
+ error_message: "Query operation cannot be performed remotely."
112
+ };
113
+ _context.next = 16;
114
+ break;
115
+ case 11:
116
+ op = folder[query.operation];
117
+ _context.next = 14;
118
+ return op(query.query, query.options);
119
+ case 14:
120
+ result = _context.sent;
121
+ folder.remote_stuff(remote, result);
122
+ case 16:
123
+ callback(result);
124
+ case 17:
125
+ case "end":
126
+ return _context.stop();
127
+ }
128
+ }, _callee);
129
+ }));
130
+ return function (_x, _x2) {
131
+ return _ref3.apply(this, arguments);
132
+ };
133
+ }());
134
+ meta = meta || {};
135
+ this.compression = meta.compression;
136
+ this.fs = _fs["default"];
137
+ this.mgr = mgr;
138
+ this.datapaths = new Object();
139
+ this.gds = new _generalisedDatastore["default"](meta.datastore || process.env.DATASTORE || "godprotocol").sync({
140
+ manager: this.mgr
141
+ });
142
+ });
143
+ var _default = Oracle;
144
+ exports["default"] = _default;