wao 0.5.5 → 0.6.0

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.
package/cjs/test.js CHANGED
@@ -40,6 +40,12 @@ Object.defineProperty(exports, "Src", {
40
40
  return _helpers.Src;
41
41
  }
42
42
  });
43
+ Object.defineProperty(exports, "Testnet", {
44
+ enumerable: true,
45
+ get: function get() {
46
+ return _helpers.Testnet;
47
+ }
48
+ });
43
49
  Object.defineProperty(exports, "acc", {
44
50
  enumerable: true,
45
51
  get: function get() {
package/cjs/tgql.js CHANGED
@@ -27,7 +27,8 @@ var subs = {
27
27
  data: ["size", "type"],
28
28
  tags: ["name", "value"],
29
29
  block: ["id", "timestamp", "height", "previous"],
30
- parent: ["id"]
30
+ parent: ["id"],
31
+ bundledIn: ["id"]
31
32
  };
32
33
  var field = function field(key) {
33
34
  var val = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
@@ -123,6 +124,9 @@ var GQL = exports["default"] = /*#__PURE__*/function () {
123
124
  _txs2,
124
125
  _iterator4,
125
126
  _step4,
127
+ _tx$recipient,
128
+ _tx$parent,
129
+ _tx$bundledIn,
126
130
  _tx$anchor,
127
131
  _tx$signature,
128
132
  v2,
@@ -174,8 +178,11 @@ var GQL = exports["default"] = /*#__PURE__*/function () {
174
178
  _block = {};
175
179
  if (!(0, _ramda.isNil)(opt.block[0])) _block.min = opt.block[0];
176
180
  if (!(0, _ramda.isNil)(opt.block[1])) _block.max = opt.block[1];
181
+ } else if ((0, _ramda.is)(Object, opt.block)) {
182
+ if (!(0, _ramda.isNil)(opt.block.min)) _block.min = opt.block.min;
183
+ if (!(0, _ramda.isNil)(opt.block.max)) _block.max = opt.block.max;
177
184
  }
178
- first = (_opt$first = opt.first) !== null && _opt$first !== void 0 ? _opt$first : 20;
185
+ first = (_opt$first = opt.first) !== null && _opt$first !== void 0 ? _opt$first : 10;
179
186
  tags = [];
180
187
  for (k in (_opt$tags = opt.tags) !== null && _opt$tags !== void 0 ? _opt$tags : {}) {
181
188
  if ((0, _ramda.is)(String, opt.tags[k])) {
@@ -346,10 +353,18 @@ var GQL = exports["default"] = /*#__PURE__*/function () {
346
353
  }
347
354
  return _context2.abrupt("continue", 97);
348
355
  case 91:
349
- _tx = _objectSpread(_objectSpread({
350
- cursor: tx.id
351
- }, tx), {}, _defineProperty({
356
+ _tx = _defineProperty({
357
+ cursor: tx.id,
358
+ id: tx.id,
359
+ recipient: (_tx$recipient = tx.recipient) !== null && _tx$recipient !== void 0 ? _tx$recipient : "",
352
360
  data: tx._data,
361
+ tags: tx.tags,
362
+ parent: (_tx$parent = tx.parent) !== null && _tx$parent !== void 0 ? _tx$parent : {
363
+ id: ""
364
+ },
365
+ bundledIn: (_tx$bundledIn = tx.bundledIn) !== null && _tx$bundledIn !== void 0 ? _tx$bundledIn : {
366
+ id: ""
367
+ },
353
368
  block: (0, _ramda.pick)(["id", "timestamp", "height", "previous"], block),
354
369
  anchor: (_tx$anchor = tx.anchor) !== null && _tx$anchor !== void 0 ? _tx$anchor : "",
355
370
  signature: (_tx$signature = tx.signature) !== null && _tx$signature !== void 0 ? _tx$signature : "",
@@ -358,17 +373,17 @@ var GQL = exports["default"] = /*#__PURE__*/function () {
358
373
  key: this.mem.addrmap[tx.owner]
359
374
  },
360
375
  fee: {
361
- ar: "0",
376
+ ar: "0.000000000000",
362
377
  winston: "0"
363
378
  },
364
379
  quantity: {
365
- ar: "0",
380
+ ar: "0.000000000000",
366
381
  winston: "0"
367
382
  }
368
383
  }, "data", {
369
384
  size: "0",
370
385
  type: ""
371
- }));
386
+ });
372
387
  if (!(0, _ramda.isNil)(opt.fields)) {
373
388
  _tx2 = {
374
389
  cursor: tx.id
package/cjs/utils.js CHANGED
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isData = exports.isCheckComplete = exports.getTagVal = exports.getTag = exports.dirname = exports.checkTag = exports.buildTags = exports.action = void 0;
7
7
  exports.isJSON = isJSON;
8
- exports.wait = exports.validAddress = exports.udl = exports.tags = exports.tagEq = exports.tag = exports.srcs = exports.searchTag = exports.mergeOut = exports.mergeChecks = exports.ltags = exports.jsonToStr = exports.isRegExp = exports.isOutComplete = exports.isLocalhost = void 0;
8
+ exports.wait = exports.validAddress = exports.udl = exports.toGraphObj = exports.tags = exports.tagEq = exports.tag = exports.srcs = exports.searchTag = exports.mergeOut = exports.mergeChecks = exports.ltags = exports.jsonToStr = exports.isRegExp = exports.isOutComplete = exports.isLocalhost = void 0;
9
+ var _graphql = require("graphql");
9
10
  var _ramda = require("ramda");
11
+ 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; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
13
+ 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); }
10
14
  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; }
11
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
12
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
@@ -455,4 +459,140 @@ function isJSON(obj) {
455
459
  }
456
460
  var jsonToStr = exports.jsonToStr = function jsonToStr(obj) {
457
461
  return isJSON(obj) || ((0, _ramda.is)(Number, obj) ? Number(obj).toString() : obj);
462
+ };
463
+ var schema = (0, _graphql.buildSchema)("\ntype Query {\n transaction(id: ID!): Transaction\n transactions(\n ids: [ID!]\n owners: [String!]\n recipients: [String!]\n tags: [TagFilter!]\n bundledIn: [ID!]\n block: BlockFilter\n first: Int = 10\n after: String\n sort: SortOrder = HEIGHT_DESC\n ): TransactionConnection!\n block(id: String): Block\n blocks(\n ids: [ID!]\n height: BlockFilter\n first: Int = 10\n after: String\n sort: SortOrder = HEIGHT_DESC\n ): BlockConnection!\n}\n\nenum SortOrder {\n HEIGHT_ASC\n HEIGHT_DESC\n}\n\ninput TagFilter {\n name: String!\n values: [String!]!\n op: TagOperator = EQ\n}\n\ninput BlockFilter {\n min: Int\n max: Int\n}\n\ntype BlockConnection {\n pageInfo: PageInfo!\n edges: [BlockEdge!]!\n}\n\ntype BlockEdge {\n cursor: String!\n node: Block!\n}\n\ntype TransactionConnection {\n pageInfo: PageInfo!\n edges: [TransactionEdge!]!\n}\n\ntype TransactionEdge {\n cursor: String!\n node: Transaction!\n}\n\ntype PageInfo {\n hasNextPage: Boolean!\n}\n\ntype Transaction {\n id: ID!\n anchor: String!\n signature: String!\n recipient: String!\n owner: Owner!\n fee: Amount!\n quantity: Amount!\n data: MetaData!\n tags: [Tag!]!\n block: Block\n parent: Parent @deprecated(reason: \"Use `bundledIn`\")\n bundledIn: Bundle\n}\n\ntype Parent {\n id: ID!\n}\n\ntype Bundle {\n id: ID!\n}\n\ntype Block {\n id: ID!\n timestamp: Int!\n height: Int!\n previous: ID!\n}\n\ntype MetaData {\n size: String!\n type: String\n}\n\ntype Amount {\n winston: String!\n ar: String!\n}\n\ntype Owner {\n address: String!\n key: String!\n}\n\ntype Tag {\n name: String!\n value: String!\n}\n\nenum TagOperator {\n EQ\n NEQ\n}\n");
464
+ var root = {
465
+ transactions: function transactions(_ref9) {
466
+ var first = _ref9.first;
467
+ return {
468
+ edges: [],
469
+ pageInfo: {
470
+ hasNextPage: false
471
+ }
472
+ };
473
+ },
474
+ block: function block(_ref10) {
475
+ var id = _ref10.id;
476
+ return {
477
+ id: id,
478
+ timestamp: Date.now(),
479
+ height: 123456,
480
+ previous: "previous-block-id",
481
+ transactions: [],
482
+ miner: "example-miner",
483
+ reward: "1000",
484
+ tags: [],
485
+ indepHash: "example-indep-hash",
486
+ nonce: "000000"
487
+ };
488
+ }
489
+ };
490
+ var mapParsed = function mapParsed(parsedQuery, variables) {
491
+ var operation = parsedQuery.definitions[0];
492
+ if (operation.operation !== "query") {
493
+ throw new Error("Only 'query' operations are supported.");
494
+ }
495
+ var rootField = operation.selectionSet.selections[0];
496
+ var rootFieldName = rootField.name.value;
497
+ var _parseArgumentValue = function parseArgumentValue(argValue) {
498
+ if (argValue.kind === "Variable") {
499
+ return variables[argValue.name.value];
500
+ }
501
+ if (argValue.kind === "ListValue") {
502
+ return argValue.values.map(function (value) {
503
+ return _parseArgumentValue(value);
504
+ });
505
+ }
506
+ if (argValue.kind === "ObjectValue") {
507
+ return argValue.fields.reduce(function (obj, field) {
508
+ obj[field.name.value] = _parseArgumentValue(field.value);
509
+ return obj;
510
+ }, {});
511
+ }
512
+ return argValue.value;
513
+ };
514
+ var args = rootField.arguments.reduce(function (acc, arg) {
515
+ acc[arg.name.value] = _parseArgumentValue(arg.value);
516
+ return acc;
517
+ }, {});
518
+ var _extractFields = function extractFields(selectionSet) {
519
+ return selectionSet.selections.map(function (selection) {
520
+ var fieldName = selection.name.value;
521
+ if (selection.selectionSet) {
522
+ return _defineProperty({}, fieldName, _extractFields(selection.selectionSet));
523
+ }
524
+ return fieldName;
525
+ });
526
+ };
527
+ var fields = _extractFields(rootField.selectionSet);
528
+ return {
529
+ rootFieldName: rootFieldName,
530
+ args: args,
531
+ fields: fields
532
+ };
533
+ };
534
+ var toGraphObj = exports.toGraphObj = function toGraphObj(_ref12) {
535
+ var query = _ref12.query,
536
+ variables = _ref12.variables;
537
+ var parsedQuery = (0, _graphql.parse)(query);
538
+ var errors = (0, _graphql.validate)(schema, parsedQuery);
539
+ var parsed = mapParsed(parsedQuery, variables);
540
+ var tar = parsed.rootFieldName;
541
+ var fields = null;
542
+ var _iterator8 = _createForOfIteratorHelper(parsed.fields),
543
+ _step8;
544
+ try {
545
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
546
+ var _v = _step8.value;
547
+ if (_v.edges) {
548
+ var _iterator10 = _createForOfIteratorHelper(_v.edges),
549
+ _step10;
550
+ try {
551
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
552
+ var v2 = _step10.value;
553
+ if (v2.node) {
554
+ fields = v2.node;
555
+ break;
556
+ }
557
+ }
558
+ } catch (err) {
559
+ _iterator10.e(err);
560
+ } finally {
561
+ _iterator10.f();
562
+ }
563
+ }
564
+ }
565
+ } catch (err) {
566
+ _iterator8.e(err);
567
+ } finally {
568
+ _iterator8.f();
569
+ }
570
+ var args = parsed.args;
571
+ if (args.block) {
572
+ for (var k in args.block) args.block[k] *= 1;
573
+ }
574
+ if (args.first) args.first *= 1;
575
+ if (fields) args.fields = fields;
576
+ if (args.sort && args.sort === "HEIGHT_ASC") args.asc = true;
577
+ delete args.sort;
578
+ if (args.tags) {
579
+ var _tags = {};
580
+ var _iterator9 = _createForOfIteratorHelper(args.tags),
581
+ _step9;
582
+ try {
583
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
584
+ var v = _step9.value;
585
+ _tags[v.name] = v.values;
586
+ }
587
+ } catch (err) {
588
+ _iterator9.e(err);
589
+ } finally {
590
+ _iterator9.f();
591
+ }
592
+ args.tags = _tags;
593
+ }
594
+ return {
595
+ tar: tar,
596
+ args: args
597
+ };
458
598
  };
package/cjs/weavedrive.js CHANGED
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports["default"] = void 0;
8
8
  var _arweave = _interopRequireDefault(require("arweave"));
9
+ var _utils = require("./utils.js");
10
+ var _ramda = require("ramda");
9
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
12
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
11
13
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -30,6 +32,7 @@ var MB = KB * 1024;
30
32
  var CACHE_SZ = 32 * KB;
31
33
  var CHUNK_SZ = 128 * MB;
32
34
  var NOTIFY_SZ = 512 * MB;
35
+ var log = console.log;
33
36
  var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDrive(ar) {
34
37
  _classCallCheck(this, WeaveDrive);
35
38
  this.drive = function WeaveDrive(mod, FS) {
@@ -123,6 +126,7 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
123
126
  create: function create(id) {
124
127
  var _this2 = this;
125
128
  return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
129
+ var _data$length;
126
130
  var properties, node, data, bytesLength, stream;
127
131
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
128
132
  while (1) switch (_context2.prev = _context2.next) {
@@ -158,7 +162,7 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
158
162
  return ar.data(id);
159
163
  case 9:
160
164
  data = _context2.sent;
161
- bytesLength = data ? new TextEncoder().encode(data).length : 100;
165
+ bytesLength = (_data$length = data === null || data === void 0 ? void 0 : data.length) !== null && _data$length !== void 0 ? _data$length : 0;
162
166
  node.total_size = Number(bytesLength);
163
167
  node.cache = new Uint8Array(0);
164
168
  node.position = 0;
@@ -569,7 +573,6 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
569
573
  read: function read(fd, raw_dst_ptr, raw_length) {
570
574
  var _this7 = this;
571
575
  return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
572
- var _yield$ar$data;
573
576
  var to_read, dst_ptr, stream, i, bytes_read, chunk_download_sz, to, data, start, end, chunk, response, reader, bytes_until_cache, bytes_until_notify, downloaded_bytes, cache_chunks, _yield$reader$read, done, chunk_bytes, write_length, chunk_to_cache;
574
577
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
575
578
  while (1) switch (_context13.prev = _context13.next) {
@@ -624,30 +627,10 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
624
627
  })
625
628
  const reader = response.body.getReader()
626
629
  */
627
- _context13.t0 = new TextEncoder();
628
- _context13.next = 22;
630
+ _context13.next = 21;
629
631
  return ar.data(stream.node.name);
630
- case 22:
631
- _context13.t2 = _yield$ar$data = _context13.sent;
632
- _context13.t1 = _context13.t2 !== null;
633
- if (!_context13.t1) {
634
- _context13.next = 26;
635
- break;
636
- }
637
- _context13.t1 = _yield$ar$data !== void 0;
638
- case 26:
639
- if (!_context13.t1) {
640
- _context13.next = 30;
641
- break;
642
- }
643
- _context13.t3 = _yield$ar$data;
644
- _context13.next = 31;
645
- break;
646
- case 30:
647
- _context13.t3 = "";
648
- case 31:
649
- _context13.t4 = _context13.t3;
650
- data = _context13.t0.encode.call(_context13.t0, _context13.t4);
632
+ case 21:
633
+ data = _context13.sent;
651
634
  // Extract the Range header to determine the start and end of the requested chunk
652
635
  start = 0;
653
636
  end = data.length; // Create a ReadableStream for the requested chunk
@@ -667,24 +650,24 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
667
650
  bytes_until_notify = NOTIFY_SZ;
668
651
  downloaded_bytes = 0;
669
652
  cache_chunks = [];
670
- _context13.prev = 42;
671
- case 43:
653
+ _context13.prev = 31;
654
+ case 32:
672
655
  if (!true) {
673
- _context13.next = 61;
656
+ _context13.next = 50;
674
657
  break;
675
658
  }
676
- _context13.next = 46;
659
+ _context13.next = 35;
677
660
  return reader.read();
678
- case 46:
661
+ case 35:
679
662
  _yield$reader$read = _context13.sent;
680
663
  done = _yield$reader$read.done;
681
664
  chunk_bytes = _yield$reader$read.value;
682
665
  if (!done) {
683
- _context13.next = 51;
666
+ _context13.next = 40;
684
667
  break;
685
668
  }
686
- return _context13.abrupt("break", 61);
687
- case 51:
669
+ return _context13.abrupt("break", 50);
670
+ case 40:
688
671
  // Update the number of downloaded bytes to be _all_, not just the write length
689
672
  downloaded_bytes += chunk_bytes.length;
690
673
  bytes_until_cache -= chunk_bytes.length;
@@ -715,20 +698,20 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
715
698
  console.log("WeaveDrive: Downloaded: ", downloaded_bytes / stream.node.total_size * 100, "%");
716
699
  bytes_until_notify = NOTIFY_SZ;
717
700
  }
718
- _context13.next = 43;
701
+ _context13.next = 32;
719
702
  break;
720
- case 61:
721
- _context13.next = 66;
703
+ case 50:
704
+ _context13.next = 55;
722
705
  break;
723
- case 63:
724
- _context13.prev = 63;
725
- _context13.t5 = _context13["catch"](42);
726
- console.error("WeaveDrive: Error reading the stream: ", _context13.t5);
727
- case 66:
728
- _context13.prev = 66;
706
+ case 52:
707
+ _context13.prev = 52;
708
+ _context13.t0 = _context13["catch"](31);
709
+ console.error("WeaveDrive: Error reading the stream: ", _context13.t0);
710
+ case 55:
711
+ _context13.prev = 55;
729
712
  reader.releaseLock();
730
- return _context13.finish(66);
731
- case 69:
713
+ return _context13.finish(55);
714
+ case 58:
732
715
  // If we have no cache, or we have not satisfied the full request, we need to download the rest
733
716
  // Rebuild the cache from the new cache chunks
734
717
  stream.node.cache = _this7.addChunksToCache(stream.node.cache, cache_chunks);
@@ -736,11 +719,11 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
736
719
  // Update the last read position
737
720
  stream.lastReadPosition = stream.position;
738
721
  return _context13.abrupt("return", bytes_read);
739
- case 72:
722
+ case 61:
740
723
  case "end":
741
724
  return _context13.stop();
742
725
  }
743
- }, _callee13, null, [[42, 63, 66, 69]]);
726
+ }, _callee13, null, [[31, 52, 55, 58]]);
744
727
  }))();
745
728
  },
746
729
  close: function close(fd) {
@@ -894,7 +877,7 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
894
877
  },
895
878
  getTagValues: function getTagValues(key, tags) {
896
879
  var values = [];
897
- for (i = 0; i < tags.length; i++) {
880
+ for (var i = 0; i < tags.length; i++) {
898
881
  if (tags[i].name == key) {
899
882
  values.push(tags[i].value);
900
883
  }
@@ -950,28 +933,71 @@ var WeaveDrive = exports["default"] = /*#__PURE__*/_createClass(function WeaveDr
950
933
  }))();
951
934
  },
952
935
  gqlQuery: function gqlQuery(query, variables) {
953
- var _this11 = this;
954
936
  return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
955
- var options;
937
+ var _json, _toGraphObj, tar, args, res2, edges;
956
938
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
957
939
  while (1) switch (_context17.prev = _context17.next) {
958
940
  case 0:
959
- options = {
960
- method: "POST",
961
- body: JSON.stringify({
962
- query: query,
963
- variables: variables
964
- }),
965
- headers: {
966
- "Content-Type": "application/json"
941
+ _json = null;
942
+ _context17.prev = 1;
943
+ _toGraphObj = (0, _utils.toGraphObj)({
944
+ query: query,
945
+ variables: variables
946
+ }), tar = _toGraphObj.tar, args = _toGraphObj.args;
947
+ res2 = null;
948
+ if (!(tar === "transactions")) {
949
+ _context17.next = 10;
950
+ break;
951
+ }
952
+ _context17.next = 7;
953
+ return ar.gql.txs(_objectSpread({}, args));
954
+ case 7:
955
+ res2 = _context17.sent;
956
+ _context17.next = 14;
957
+ break;
958
+ case 10:
959
+ if (!(tar === "blocks")) {
960
+ _context17.next = 14;
961
+ break;
962
+ }
963
+ _context17.next = 13;
964
+ return ar.gql.blocks(_objectSpread({}, args));
965
+ case 13:
966
+ res2 = _context17.sent;
967
+ case 14:
968
+ edges = (0, _ramda.map)(function (v) {
969
+ return {
970
+ node: v,
971
+ cursor: v.cursor
972
+ };
973
+ }, res2);
974
+ _json = {
975
+ data: {
976
+ transactions: {
977
+ pageInfo: {
978
+ hasNextPage: true
979
+ },
980
+ edges: edges
981
+ }
967
982
  }
968
983
  };
969
- return _context17.abrupt("return", _this11.customFetch("graphql", options));
970
- case 2:
984
+ _context17.next = 21;
985
+ break;
986
+ case 18:
987
+ _context17.prev = 18;
988
+ _context17.t0 = _context17["catch"](1);
989
+ log(_context17.t0);
990
+ case 21:
991
+ return _context17.abrupt("return", {
992
+ json: function json() {
993
+ return _json;
994
+ }
995
+ });
996
+ case 22:
971
997
  case "end":
972
998
  return _context17.stop();
973
999
  }
974
- }, _callee17);
1000
+ }, _callee17, null, [[1, 18]]);
975
1001
  }))();
976
1002
  }
977
1003
  };
package/esm/ao.js CHANGED
@@ -287,6 +287,7 @@ class AO {
287
287
  "Output-Encoding": "JSON-V1",
288
288
  "Memory-Limit": "1-gb",
289
289
  "Compute-Limit": "9000000000000",
290
+ Extension: "WeaveDrive",
290
291
  })
291
292
 
292
293
  const fns = [
@@ -625,6 +626,28 @@ class AO {
625
626
  }
626
627
  return { err, pid }
627
628
  }
629
+ async attest({ id, jwk, tags }) {
630
+ return await this.ar.post({
631
+ tags: mergeLeft(tags, {
632
+ "Data-Protocol": "ao",
633
+ Type: "Attestation",
634
+ Message: id,
635
+ }),
636
+ jwk,
637
+ })
638
+ }
639
+
640
+ async avail({ ids, jwk, tags }) {
641
+ return await this.ar.post({
642
+ tags: mergeLeft(tags, {
643
+ "Data-Protocol": "WeaveDrive",
644
+ Variant: "WeaveDrive.tn.1",
645
+ Type: "Available",
646
+ ID: ids,
647
+ }),
648
+ jwk,
649
+ })
650
+ }
628
651
 
629
652
  async deploy({
630
653
  boot,
@@ -670,7 +693,9 @@ class AO {
670
693
  : []
671
694
  : loads) {
672
695
  if (!isBoot || i !== 0) {
673
- fns.push({ fn: this.load, args: v, then: { "args.pid": "pid" } })
696
+ let args = v
697
+ if (typeof args === "string") args = { data: v }
698
+ fns.push({ fn: this.load, args, then: { "args.pid": "pid" } })
674
699
  }
675
700
  i++
676
701
  }
@@ -709,6 +734,10 @@ class Process {
709
734
  this.ao = ao
710
735
  this.pid = pid
711
736
  }
737
+
738
+ async load(opt = {}) {
739
+ return await this.ao.load({ pid: this.pid, ...opt })
740
+ }
712
741
  async msg(act, tags, opts) {
713
742
  const { _tags, _opts } = getParams(tags, opts)
714
743
  return await this.ao.msg({ pid: this.pid, act, tags: _tags, ..._opts })
package/esm/aoconnect.js CHANGED
@@ -23,7 +23,7 @@ import { scheduler, mu, su, cu, acc } from "./test.js"
23
23
  import { is, clone, fromPairs, map, mergeLeft, isNil } from "ramda"
24
24
  import AR from "./tar.js"
25
25
 
26
- export const connect = mem => {
26
+ export const connect = (mem, log = false) => {
27
27
  const isMem = mem?.__type__ === "mem"
28
28
  if (!isMem) {
29
29
  let args = {}
@@ -33,7 +33,7 @@ export const connect = mem => {
33
33
  }
34
34
  mem = new ArMem(args)
35
35
  }
36
- const ar = new AR({ mem })
36
+ const ar = new AR({ mem, log })
37
37
  const WeaveDrive = new weavedrive(ar).drive
38
38
 
39
39
  const transform = input => {
@@ -62,7 +62,7 @@ export const connect = mem => {
62
62
  Target: p.id,
63
63
  Owner,
64
64
  Data: data?.length ? data : "",
65
- "Block-Height": p.height.toString(),
65
+ "Block-Height": mem.height.toString(),
66
66
  Timestamp: Date.now().toString(),
67
67
  Module: p.module,
68
68
  From: from,
@@ -116,14 +116,7 @@ export const connect = mem => {
116
116
  format = mem.wasms[mod].format
117
117
  }
118
118
  format ??= "wasm64-unknown-emscripten-draft_2024_02_15"
119
- const now = Date.now
120
- const handle = await AoLoader(wasm, {
121
- format,
122
- mode: "test",
123
- WeaveDrive,
124
- })
125
- Date.now = now
126
- _module = { handle, id: mod }
119
+
127
120
  if (!mod) throw Error("module not found")
128
121
  opt.tags = buildTags(
129
122
  null,
@@ -132,7 +125,7 @@ export const connect = mem => {
132
125
  Variant: "ao.TN.1",
133
126
  Type: "Process",
134
127
  SDK: "aoconnect",
135
- Module: opt.module,
128
+ Module: mod,
136
129
  Scheduler: opt.scheduler,
137
130
  "Content-Type": "text/plain",
138
131
  }),
@@ -154,7 +147,18 @@ export const connect = mem => {
154
147
  })
155
148
  opt.tags = buildTags(null, __tags)
156
149
  if (opt.item) opt.data = base64url.decode(item.data)
157
- await ar.postItem(item, su.jwk)
150
+ await ar.postItems(item, su.jwk)
151
+ const now = Date.now
152
+ const handle = await AoLoader(wasm, {
153
+ format,
154
+ WeaveDrive,
155
+ spawn: item,
156
+ module: mem.txs[mod],
157
+ blockHeight: "100",
158
+ })
159
+ _module = { handle, id: mod }
160
+ Date.now = now
161
+
158
162
  const _tags = tags(opt.tags)
159
163
  let res = null
160
164
  let memory = null
@@ -270,7 +274,11 @@ export const connect = mem => {
270
274
  tags: tags(opt.tags),
271
275
  target: opt.process,
272
276
  })
273
- await ar.postItem(item, su.jwk)
277
+ if (opt.message_item) {
278
+ await ar.postItems([opt.message_item, item], su.jwk)
279
+ } else {
280
+ await ar.postItems(item, su.jwk)
281
+ }
274
282
  try {
275
283
  let data = _opt.data ?? ""
276
284
  let _tags = _opt.tags
@@ -370,9 +378,10 @@ export const connect = mem => {
370
378
  target: opt.process,
371
379
  }))
372
380
  }
373
- await ar.postItem(item, su.jwk)
381
+ //await ar.postItems(item, su.jwk)
374
382
  mem.msgs[id] = opt
375
383
  await assign({
384
+ message_item: item,
376
385
  message: id,
377
386
  process: opt.process,
378
387
  from: owner,