wao 0.10.3 → 0.10.5

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/server.js CHANGED
@@ -340,6 +340,22 @@ var Server = /*#__PURE__*/function () {
340
340
  return _ref8.apply(this, arguments);
341
341
  };
342
342
  }());
343
+ app.get("*", /*#__PURE__*/function () {
344
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(req, res) {
345
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
346
+ while (1) switch (_context8.prev = _context8.next) {
347
+ case 0:
348
+ console.log("what");
349
+ case 1:
350
+ case "end":
351
+ return _context8.stop();
352
+ }
353
+ }, _callee8);
354
+ }));
355
+ return function (_x15, _x16) {
356
+ return _ref9.apply(this, arguments);
357
+ };
358
+ }());
343
359
  var server = app.listen(this.ports.ar, function () {
344
360
  console.log("AR on port ".concat(_this.ports.ar));
345
361
  });
@@ -358,11 +374,11 @@ var Server = /*#__PURE__*/function () {
358
374
  return res.send("ao messenger unit");
359
375
  });
360
376
  app.post("/monitor/:id", /*#__PURE__*/function () {
361
- var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(req, res) {
362
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
363
- while (1) switch (_context8.prev = _context8.next) {
377
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(req, res) {
378
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
379
+ while (1) switch (_context9.prev = _context9.next) {
364
380
  case 0:
365
- _context8.next = 2;
381
+ _context9.next = 2;
366
382
  return _this2.monitor({
367
383
  process: req.params.id
368
384
  });
@@ -373,20 +389,20 @@ var Server = /*#__PURE__*/function () {
373
389
  });
374
390
  case 3:
375
391
  case "end":
376
- return _context8.stop();
392
+ return _context9.stop();
377
393
  }
378
- }, _callee8);
394
+ }, _callee9);
379
395
  }));
380
- return function (_x15, _x16) {
381
- return _ref9.apply(this, arguments);
396
+ return function (_x17, _x18) {
397
+ return _ref10.apply(this, arguments);
382
398
  };
383
399
  }());
384
400
  app["delete"]("/monitor/:id", /*#__PURE__*/function () {
385
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(req, res) {
386
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
387
- while (1) switch (_context9.prev = _context9.next) {
401
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(req, res) {
402
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
403
+ while (1) switch (_context10.prev = _context10.next) {
388
404
  case 0:
389
- _context9.next = 2;
405
+ _context10.next = 2;
390
406
  return _this2.unmonitor({
391
407
  process: req.params.id
392
408
  });
@@ -397,57 +413,57 @@ var Server = /*#__PURE__*/function () {
397
413
  });
398
414
  case 3:
399
415
  case "end":
400
- return _context9.stop();
416
+ return _context10.stop();
401
417
  }
402
- }, _callee9);
418
+ }, _callee10);
403
419
  }));
404
- return function (_x17, _x18) {
405
- return _ref10.apply(this, arguments);
420
+ return function (_x19, _x20) {
421
+ return _ref11.apply(this, arguments);
406
422
  };
407
423
  }());
408
424
  app.post("/", /*#__PURE__*/function () {
409
- var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(req, res) {
410
- var binary, valid, type, item, _tags, err, _res;
411
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
412
- while (1) switch (_context10.prev = _context10.next) {
425
+ var _ref12 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(req, res) {
426
+ var binary, valid, type, item, _tags, err, _res2;
427
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
428
+ while (1) switch (_context11.prev = _context11.next) {
413
429
  case 0:
414
430
  binary = req.body;
415
- _context10.next = 3;
431
+ _context11.next = 3;
416
432
  return _arbundles.DataItem.verify(binary);
417
433
  case 3:
418
- valid = _context10.sent;
434
+ valid = _context11.sent;
419
435
  type = null;
420
436
  item = null;
421
437
  if (valid) item = new _arbundles.DataItem(binary);
422
438
  _tags = (0, _utils.tags)(item.tags);
423
439
  err = null;
424
440
  if (!(_tags.Type === "Process")) {
425
- _context10.next = 16;
441
+ _context11.next = 16;
426
442
  break;
427
443
  }
428
- _context10.next = 12;
444
+ _context11.next = 12;
429
445
  return _this2.spawn({
430
446
  item: item,
431
447
  module: _tags.Module,
432
448
  scheduler: _tags.Scheduler
433
449
  });
434
450
  case 12:
435
- _res = _context10.sent;
436
- if (!_res) err = "bad requrest";
437
- _context10.next = 22;
451
+ _res2 = _context11.sent;
452
+ if (!_res2) err = "bad requrest";
453
+ _context11.next = 22;
438
454
  break;
439
455
  case 16:
440
456
  if (!(_tags.Type === "Message")) {
441
- _context10.next = 21;
457
+ _context11.next = 21;
442
458
  break;
443
459
  }
444
- _context10.next = 19;
460
+ _context11.next = 19;
445
461
  return _this2.message({
446
462
  item: item,
447
463
  process: item.target
448
464
  });
449
465
  case 19:
450
- _context10.next = 22;
466
+ _context11.next = 22;
451
467
  break;
452
468
  case 21:
453
469
  err = true;
@@ -464,12 +480,12 @@ var Server = /*#__PURE__*/function () {
464
480
  }
465
481
  case 23:
466
482
  case "end":
467
- return _context10.stop();
483
+ return _context11.stop();
468
484
  }
469
- }, _callee10);
485
+ }, _callee11);
470
486
  }));
471
- return function (_x19, _x20) {
472
- return _ref11.apply(this, arguments);
487
+ return function (_x21, _x22) {
488
+ return _ref12.apply(this, arguments);
473
489
  };
474
490
  }());
475
491
  var server = app.listen(this.ports.mu, function () {
@@ -502,23 +518,23 @@ var Server = /*#__PURE__*/function () {
502
518
  var _this3$mem$env$pid$re, _this3$mem$env$pid;
503
519
  var pid = req.params.pid;
504
520
  var edges = (0, _ramda.map)(/*#__PURE__*/function () {
505
- var _ref12 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(v) {
521
+ var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(v) {
506
522
  var _mtx$anchor, _tx$anchor;
507
523
  var tx, _tags, mid, mtx;
508
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
509
- while (1) switch (_context11.prev = _context11.next) {
524
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
525
+ while (1) switch (_context12.prev = _context12.next) {
510
526
  case 0:
511
- _context11.next = 2;
527
+ _context12.next = 2;
512
528
  return _this3.mem.getTx(v);
513
529
  case 2:
514
- tx = _context11.sent;
530
+ tx = _context12.sent;
515
531
  _tags = (0, _utils.tags)(v.tags);
516
532
  mid = _tags.Message;
517
- _context11.next = 7;
533
+ _context12.next = 7;
518
534
  return _this3.mem.getTx(mid);
519
535
  case 7:
520
- mtx = _context11.sent;
521
- return _context11.abrupt("return", {
536
+ mtx = _context12.sent;
537
+ return _context12.abrupt("return", {
522
538
  cursor: v,
523
539
  node: {
524
540
  message: {
@@ -542,12 +558,12 @@ var Server = /*#__PURE__*/function () {
542
558
  });
543
559
  case 9:
544
560
  case "end":
545
- return _context11.stop();
561
+ return _context12.stop();
546
562
  }
547
- }, _callee11);
563
+ }, _callee12);
548
564
  }));
549
- return function (_x21) {
550
- return _ref12.apply(this, arguments);
565
+ return function (_x23) {
566
+ return _ref13.apply(this, arguments);
551
567
  };
552
568
  }())((0, _ramda.reverse)((_this3$mem$env$pid$re = (_this3$mem$env$pid = _this3.mem.env[pid]) === null || _this3$mem$env$pid === void 0 ? void 0 : _this3$mem$env$pid.results) !== null && _this3$mem$env$pid$re !== void 0 ? _this3$mem$env$pid$re : [])); // need mod
553
569
  res.json({
@@ -557,6 +573,22 @@ var Server = /*#__PURE__*/function () {
557
573
  edges: edges
558
574
  });
559
575
  });
576
+ app.get("*", /*#__PURE__*/function () {
577
+ var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(req, res) {
578
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
579
+ while (1) switch (_context13.prev = _context13.next) {
580
+ case 0:
581
+ console.log("what2");
582
+ case 1:
583
+ case "end":
584
+ return _context13.stop();
585
+ }
586
+ }, _callee13);
587
+ }));
588
+ return function (_x24, _x25) {
589
+ return _ref14.apply(this, arguments);
590
+ };
591
+ }());
560
592
  var server = app.listen(this.ports.su, function () {
561
593
  return console.log("SU on port ".concat(_this3.ports.su));
562
594
  });
@@ -576,38 +608,86 @@ var Server = /*#__PURE__*/function () {
576
608
  });
577
609
  });
578
610
  app.get("/result/:mid", /*#__PURE__*/function () {
579
- var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(req, res) {
611
+ var _ref15 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(req, res) {
580
612
  var res2;
581
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
582
- while (1) switch (_context12.prev = _context12.next) {
613
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
614
+ while (1) switch (_context14.prev = _context14.next) {
583
615
  case 0:
584
- _context12.next = 2;
616
+ _context14.next = 2;
585
617
  return _this4.result({
586
618
  message: req.params.mid,
587
619
  process: req.query["process-id"]
588
620
  });
589
621
  case 2:
590
- res2 = _context12.sent;
622
+ res2 = _context14.sent;
591
623
  res.json(res2);
592
624
  case 4:
593
625
  case "end":
594
- return _context12.stop();
626
+ return _context14.stop();
595
627
  }
596
- }, _callee12);
628
+ }, _callee14);
597
629
  }));
598
- return function (_x22, _x23) {
599
- return _ref13.apply(this, arguments);
630
+ return function (_x26, _x27) {
631
+ return _ref15.apply(this, arguments);
632
+ };
633
+ }());
634
+ app.get("/state/:pid", /*#__PURE__*/function () {
635
+ var _ref16 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(req, res) {
636
+ var _yield$_this4$mem$env, _this4$mem$env$pid;
637
+ var pid, memory;
638
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
639
+ while (1) switch (_context15.prev = _context15.next) {
640
+ case 0:
641
+ pid = req.params.pid;
642
+ _context15.next = 3;
643
+ return (_this4$mem$env$pid = _this4.mem.env[pid]) === null || _this4$mem$env$pid === void 0 ? void 0 : _this4$mem$env$pid.memory;
644
+ case 3:
645
+ _context15.t1 = _yield$_this4$mem$env = _context15.sent;
646
+ _context15.t0 = _context15.t1 !== null;
647
+ if (!_context15.t0) {
648
+ _context15.next = 7;
649
+ break;
650
+ }
651
+ _context15.t0 = _yield$_this4$mem$env !== void 0;
652
+ case 7:
653
+ if (!_context15.t0) {
654
+ _context15.next = 11;
655
+ break;
656
+ }
657
+ _context15.t2 = _yield$_this4$mem$env;
658
+ _context15.next = 12;
659
+ break;
660
+ case 11:
661
+ _context15.t2 = null;
662
+ case 12:
663
+ memory = _context15.t2;
664
+ if (!memory) {
665
+ res.status(404);
666
+ res.json({
667
+ error: "TransactionNotFound: Process ".concat(pid, " was not found on gateway")
668
+ });
669
+ } else {
670
+ res.send(Buffer.from(memory));
671
+ }
672
+ case 14:
673
+ case "end":
674
+ return _context15.stop();
675
+ }
676
+ }, _callee15);
677
+ }));
678
+ return function (_x28, _x29) {
679
+ return _ref16.apply(this, arguments);
600
680
  };
601
681
  }());
602
682
  app.post("/dry-run", /*#__PURE__*/function () {
603
- var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(req, res) {
683
+ var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee16(req, res) {
604
684
  var process, _req$body2, id, owner, tags, data, res2;
605
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
606
- while (1) switch (_context13.prev = _context13.next) {
685
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
686
+ while (1) switch (_context16.prev = _context16.next) {
607
687
  case 0:
608
688
  process = req.query["process-id"];
609
689
  _req$body2 = req.body, id = _req$body2.Id, owner = _req$body2.Owner, tags = _req$body2.Tags, data = _req$body2.Data;
610
- _context13.next = 4;
690
+ _context16.next = 4;
611
691
  return _this4.dryrun({
612
692
  id: id,
613
693
  owner: owner,
@@ -616,7 +696,7 @@ var Server = /*#__PURE__*/function () {
616
696
  process: process
617
697
  });
618
698
  case 4:
619
- res2 = _context13.sent;
699
+ res2 = _context16.sent;
620
700
  if (!res2) {
621
701
  res.status(400);
622
702
  res.json({
@@ -628,12 +708,91 @@ var Server = /*#__PURE__*/function () {
628
708
  }
629
709
  case 6:
630
710
  case "end":
631
- return _context13.stop();
711
+ return _context16.stop();
632
712
  }
633
- }, _callee13);
713
+ }, _callee16);
634
714
  }));
635
- return function (_x24, _x25) {
636
- return _ref14.apply(this, arguments);
715
+ return function (_x30, _x31) {
716
+ return _ref17.apply(this, arguments);
717
+ };
718
+ }());
719
+ app.get("/results/:pid", /*#__PURE__*/function () {
720
+ var _ref18 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee17(req, res) {
721
+ var _this4$mem$env$pid$re, _this4$mem$env$pid2;
722
+ var pid, _req$query, _req$query$from, from, _req$query$to, to, _req$query$sort, sort, _req$query$limit, limit, results, _res, i, count, started, _iterator, _step, v, _this4$mem$msgs$v;
723
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
724
+ while (1) switch (_context17.prev = _context17.next) {
725
+ case 0:
726
+ pid = req.params.pid;
727
+ _req$query = req.query, _req$query$from = _req$query.from, from = _req$query$from === void 0 ? null : _req$query$from, _req$query$to = _req$query.to, to = _req$query$to === void 0 ? null : _req$query$to, _req$query$sort = _req$query.sort, sort = _req$query$sort === void 0 ? "ASC" : _req$query$sort, _req$query$limit = _req$query.limit, limit = _req$query$limit === void 0 ? 25 : _req$query$limit;
728
+ results = (_this4$mem$env$pid$re = (_this4$mem$env$pid2 = _this4.mem.env[pid]) === null || _this4$mem$env$pid2 === void 0 ? void 0 : _this4$mem$env$pid2.results) !== null && _this4$mem$env$pid$re !== void 0 ? _this4$mem$env$pid$re : [];
729
+ if (sort.toLowerCase() === "desc") results = (0, _ramda.reverse)(results);
730
+ _res = [];
731
+ i = 1;
732
+ count = 0;
733
+ started = (0, _ramda.isNil)(from);
734
+ _iterator = _createForOfIteratorHelper(results);
735
+ _context17.prev = 9;
736
+ _iterator.s();
737
+ case 11:
738
+ if ((_step = _iterator.n()).done) {
739
+ _context17.next = 26;
740
+ break;
741
+ }
742
+ v = _step.value;
743
+ if (!started) {
744
+ _context17.next = 22;
745
+ break;
746
+ }
747
+ _res.push({
748
+ cursor: v,
749
+ node: (_this4$mem$msgs$v = _this4.mem.msgs[v]) === null || _this4$mem$msgs$v === void 0 ? void 0 : _this4$mem$msgs$v.res
750
+ });
751
+ count++;
752
+ if (!(!(0, _ramda.isNil)(to) && v === to)) {
753
+ _context17.next = 18;
754
+ break;
755
+ }
756
+ return _context17.abrupt("break", 26);
757
+ case 18:
758
+ if (!(limit <= count)) {
759
+ _context17.next = 20;
760
+ break;
761
+ }
762
+ return _context17.abrupt("break", 26);
763
+ case 20:
764
+ _context17.next = 23;
765
+ break;
766
+ case 22:
767
+ if (from === v) started = true;
768
+ case 23:
769
+ i++;
770
+ case 24:
771
+ _context17.next = 11;
772
+ break;
773
+ case 26:
774
+ _context17.next = 31;
775
+ break;
776
+ case 28:
777
+ _context17.prev = 28;
778
+ _context17.t0 = _context17["catch"](9);
779
+ _iterator.e(_context17.t0);
780
+ case 31:
781
+ _context17.prev = 31;
782
+ _iterator.f();
783
+ return _context17.finish(31);
784
+ case 34:
785
+ res.json({
786
+ edges: _res
787
+ });
788
+ case 35:
789
+ case "end":
790
+ return _context17.stop();
791
+ }
792
+ }, _callee17, null, [[9, 28, 31, 34]]);
793
+ }));
794
+ return function (_x32, _x33) {
795
+ return _ref18.apply(this, arguments);
637
796
  };
638
797
  }());
639
798
  var server = app.listen(this.ports.cu, function () {
@@ -647,11 +806,11 @@ var Server = /*#__PURE__*/function () {
647
806
  var _this5 = this;
648
807
  return new Promise(function (res) {
649
808
  var count = 0;
650
- var _iterator = _createForOfIteratorHelper(_this5.servers),
651
- _step;
809
+ var _iterator2 = _createForOfIteratorHelper(_this5.servers),
810
+ _step2;
652
811
  try {
653
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
654
- var v = _step.value;
812
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
813
+ var v = _step2.value;
655
814
  v.close(function () {
656
815
  count += 1;
657
816
  if (count >= 4) {
@@ -661,9 +820,9 @@ var Server = /*#__PURE__*/function () {
661
820
  });
662
821
  }
663
822
  } catch (err) {
664
- _iterator.e(err);
823
+ _iterator2.e(err);
665
824
  } finally {
666
- _iterator.f();
825
+ _iterator2.f();
667
826
  }
668
827
  });
669
828
  }
package/esm/server.js CHANGED
@@ -6,7 +6,7 @@ import { tags, toGraphObj, optAO } from "./utils.js"
6
6
  import { connect } from "./aoconnect.js"
7
7
  import { GQL, cu, su, mu } from "./test.js"
8
8
  import bodyParser from "body-parser"
9
- import { keys, map, reverse } from "ramda"
9
+ import { keys, map, isNil, reverse } from "ramda"
10
10
 
11
11
  class Server {
12
12
  constructor({
@@ -148,7 +148,9 @@ class Server {
148
148
  res.json({ id: req.body.id })
149
149
  }
150
150
  })
151
-
151
+ app.get("*", async (req, res) => {
152
+ console.log("what")
153
+ })
152
154
  const server = app.listen(this.ports.ar, () => {
153
155
  console.log(`AR on port ${this.ports.ar}`)
154
156
  })
@@ -246,6 +248,10 @@ class Server {
246
248
  })(reverse(this.mem.env[pid]?.results ?? [])) // need mod
247
249
  res.json({ page_info: { has_next_page: false }, edges })
248
250
  })
251
+ app.get("*", async (req, res) => {
252
+ console.log("what2")
253
+ })
254
+
249
255
  const server = app.listen(this.ports.su, () =>
250
256
  console.log(`SU on port ${this.ports.su}`),
251
257
  )
@@ -265,6 +271,18 @@ class Server {
265
271
  })
266
272
  res.json(res2)
267
273
  })
274
+ app.get("/state/:pid", async (req, res) => {
275
+ const pid = req.params.pid
276
+ const memory = (await this.mem.env[pid]?.memory) ?? null
277
+ if (!memory) {
278
+ res.status(404)
279
+ res.json({
280
+ error: `TransactionNotFound: Process ${pid} was not found on gateway`,
281
+ })
282
+ } else {
283
+ res.send(Buffer.from(memory))
284
+ }
285
+ })
268
286
  app.post("/dry-run", async (req, res) => {
269
287
  const process = req.query["process-id"]
270
288
  const { Id: id, Owner: owner, Tags: tags, Data: data } = req.body
@@ -277,6 +295,28 @@ class Server {
277
295
  res.json(res2)
278
296
  }
279
297
  })
298
+ app.get("/results/:pid", async (req, res) => {
299
+ const pid = req.params.pid
300
+ const { from = null, to = null, sort = "ASC", limit = 25 } = req.query
301
+ let results = this.mem.env[pid]?.results ?? []
302
+ if (sort.toLowerCase() === "desc") results = reverse(results)
303
+ let _res = []
304
+ let i = 1
305
+ let count = 0
306
+ let started = isNil(from)
307
+ for (let v of results) {
308
+ if (started) {
309
+ _res.push({ cursor: v, node: this.mem.msgs[v]?.res })
310
+ count++
311
+ if (!isNil(to) && v === to) break
312
+ if (limit <= count) break
313
+ } else if (from === v) started = true
314
+
315
+ i++
316
+ }
317
+ res.json({ edges: _res })
318
+ })
319
+
280
320
  const server = app.listen(this.ports.cu, () =>
281
321
  console.log(`CU on port ${this.ports.cu}`),
282
322
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wao",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "bin": {
5
5
  "wao": "./cjs/cli.js",
6
6
  "wao-esm": "./esm/cli.js"