wao 0.36.6 → 0.37.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/hb.js CHANGED
@@ -11,7 +11,6 @@ var _utils = require("./utils.js");
11
11
  var _hbsig = require("hbsig");
12
12
  var _hyperAos = _interopRequireDefault(require("./hyper-aos.js"));
13
13
  var _aos_wamr = _interopRequireDefault(require("./aos_wamr.js"));
14
- var _httpsigUtils = require("./httpsig-utils.js");
15
14
  var _sdk = require("@ar.io/sdk");
16
15
  var _arbundles = require("@dha-team/arbundles");
17
16
  var _excluded = ["path"],
@@ -41,8 +40,8 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
41
40
  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); }); }; }
42
41
  var toMsg = /*#__PURE__*/function () {
43
42
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
44
- var _req$headers, _req$text;
45
- var msg;
43
+ var _req$headers;
44
+ var msg, arrayBuffer;
46
45
  return _regeneratorRuntime().wrap(function _callee$(_context) {
47
46
  while (1) switch (_context.prev = _context.next) {
48
47
  case 0:
@@ -50,17 +49,20 @@ var toMsg = /*#__PURE__*/function () {
50
49
  req === null || req === void 0 || (_req$headers = req.headers) === null || _req$headers === void 0 || _req$headers.forEach(function (v, k) {
51
50
  msg[k] = v;
52
51
  });
52
+ //if (req.body) msg.body = await req.text?.()
53
53
  if (!req.body) {
54
- _context.next = 6;
54
+ _context.next = 7;
55
55
  break;
56
56
  }
57
57
  _context.next = 5;
58
- return (_req$text = req.text) === null || _req$text === void 0 ? void 0 : _req$text.call(req);
58
+ return req.arrayBuffer();
59
59
  case 5:
60
- msg.body = _context.sent;
61
- case 6:
62
- return _context.abrupt("return", msg);
60
+ arrayBuffer = _context.sent;
61
+ msg.body = typeof Buffer !== "undefined" ? Buffer.from(arrayBuffer) // Node.js
62
+ : new Uint8Array(arrayBuffer); // Browser
63
63
  case 7:
64
+ return _context.abrupt("return", msg);
65
+ case 8:
64
66
  case "end":
65
67
  return _context.stop();
66
68
  }
@@ -693,16 +695,11 @@ var HB = /*#__PURE__*/function () {
693
695
  });
694
696
  case 3:
695
697
  res = _context19.sent;
696
- _context19.t0 = _hbsig.structured_to;
697
- _context19.t1 = _hbsig.httpsig_from;
698
- _context19.next = 8;
699
- return toMsg(res);
700
- case 8:
701
- _context19.t2 = _context19.sent;
702
- _context19.t3 = (0, _context19.t1)(_context19.t2);
703
- res.out = (0, _context19.t0)(_context19.t3);
704
- return _context19.abrupt("return", res);
705
- case 12:
698
+ _context19.next = 6;
699
+ return (0, _hbsig.result)(res);
700
+ case 6:
701
+ return _context19.abrupt("return", _context19.sent);
702
+ case 7:
706
703
  case "end":
707
704
  return _context19.stop();
708
705
  }
@@ -1498,8 +1495,6 @@ var HB = /*#__PURE__*/function () {
1498
1495
  i,
1499
1496
  k,
1500
1497
  response,
1501
- headers,
1502
- http,
1503
1498
  _args38 = arguments;
1504
1499
  return _regeneratorRuntime().wrap(function _callee37$(_context37) {
1505
1500
  while (1) switch (_context37.prev = _context37.next) {
@@ -1521,23 +1516,11 @@ var HB = /*#__PURE__*/function () {
1521
1516
  return fetch("".concat(this.url).concat(path).concat(_json).concat(_params));
1522
1517
  case 9:
1523
1518
  response = _context37.sent;
1524
- headers = {};
1525
- response.headers.forEach(function (v, k) {
1526
- return headers[k] = v;
1527
- });
1528
- _context37.t0 = headers;
1529
- _context37.next = 15;
1530
- return response.text();
1531
- case 15:
1532
- _context37.t1 = _context37.sent;
1533
- _context37.t2 = response.status;
1534
- http = {
1535
- headers: _context37.t0,
1536
- body: _context37.t1,
1537
- status: _context37.t2
1538
- };
1539
- return _context37.abrupt("return", _objectSpread(_objectSpread({}, (0, _httpsigUtils.from)(http)), http));
1540
- case 19:
1519
+ _context37.next = 12;
1520
+ return (0, _hbsig.result)(response);
1521
+ case 12:
1522
+ return _context37.abrupt("return", _context37.sent);
1523
+ case 13:
1541
1524
  case "end":
1542
1525
  return _context37.stop();
1543
1526
  }
@@ -9,7 +9,7 @@
9
9
  "deploy": "node scripts/deploy.js"
10
10
  },
11
11
  "dependencies": {
12
- "hbsig": "^0.1.4",
13
- "wao": "^0.35.7"
12
+ "hbsig": "^0.2.0",
13
+ "wao": "^0.37.0"
14
14
  }
15
15
  }
package/esm/hb.js CHANGED
@@ -10,11 +10,10 @@ import {
10
10
  signer,
11
11
  send as _send,
12
12
  commit,
13
+ result,
13
14
  } from "hbsig"
14
15
  import hyper_aos from "./hyper-aos.js"
15
16
  import aos_wamr from "./aos_wamr.js"
16
- import { from } from "./httpsig-utils.js"
17
-
18
17
  import { ArweaveSigner } from "@ar.io/sdk"
19
18
  import { createData } from "@dha-team/arbundles"
20
19
 
@@ -23,7 +22,14 @@ const toMsg = async req => {
23
22
  req?.headers?.forEach((v, k) => {
24
23
  msg[k] = v
25
24
  })
26
- if (req.body) msg.body = await req.text?.()
25
+ //if (req.body) msg.body = await req.text?.()
26
+ if (req.body) {
27
+ const arrayBuffer = await req.arrayBuffer()
28
+ msg.body =
29
+ typeof Buffer !== "undefined"
30
+ ? Buffer.from(arrayBuffer) // Node.js
31
+ : new Uint8Array(arrayBuffer) // Browser
32
+ }
27
33
  return msg
28
34
  }
29
35
 
@@ -177,8 +183,7 @@ class HB {
177
183
  },
178
184
  body: item.binary,
179
185
  })
180
- res.out = structured_to(httpsig_from(await toMsg(res)))
181
- return res
186
+ return await result(res)
182
187
  }
183
188
  async post104({
184
189
  path = "/~process@1.0/schedule",
@@ -393,17 +398,7 @@ class HB {
393
398
  }
394
399
  }
395
400
  const response = await fetch(`${this.url}${path}${_json}${_params}`)
396
- let headers = {}
397
- response.headers.forEach((v, k) => (headers[k] = v))
398
- const http = {
399
- headers,
400
- body: await response.text(),
401
- status: response.status,
402
- }
403
- return {
404
- ...from(http),
405
- ...http,
406
- }
401
+ return await result(response)
407
402
  }
408
403
 
409
404
  async postJSON(args, opt = {}) {
@@ -9,7 +9,7 @@
9
9
  "deploy": "node scripts/deploy.js"
10
10
  },
11
11
  "dependencies": {
12
- "hbsig": "^0.1.4",
13
- "wao": "^0.35.7"
12
+ "hbsig": "^0.2.0",
13
+ "wao": "^0.37.0"
14
14
  }
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wao",
3
- "version": "0.36.6",
3
+ "version": "0.37.0",
4
4
  "bin": {
5
5
  "wao": "./cjs/cli.js",
6
6
  "wao-esm": "./esm/cli.js"
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = encodeArrayItem;
7
- var _encodeUtils = require("./encode-utils.js");
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
- // Helper to generate the correct number of backslashes for a given nesting level
10
- function getBackslashes(level) {
11
- return "\\".repeat(Math.pow(2, level) - 1);
12
- }
13
-
14
- // Helper to encode primitive values at a specific nesting level
15
- function encodePrimitiveAtLevel(value, level) {
16
- var bs = getBackslashes(level);
17
- if (typeof value === "number") {
18
- if (Number.isInteger(value)) {
19
- return "".concat(bs, "\"(ao-type-integer) ").concat(value).concat(bs, "\"");
20
- } else {
21
- return "".concat(bs, "\"(ao-type-float) ").concat((0, _encodeUtils.formatFloat)(value)).concat(bs, "\"");
22
- }
23
- } else if (typeof value === "string") {
24
- return "".concat(bs, "\"").concat(value).concat(bs, "\"");
25
- } else if (value === null) {
26
- var innerBs = getBackslashes(level + 1);
27
- return "".concat(bs, "\"(ao-type-atom) ").concat(innerBs, "\"null").concat(innerBs, "\"").concat(bs, "\"");
28
- } else if (value === undefined) {
29
- var _innerBs = getBackslashes(level + 1);
30
- return "".concat(bs, "\"(ao-type-atom) ").concat(_innerBs, "\"undefined").concat(_innerBs, "\"").concat(bs, "\"");
31
- } else if (_typeof(value) === "symbol") {
32
- var desc = value.description || "Symbol.for()";
33
- var _innerBs2 = getBackslashes(level + 1);
34
- return "".concat(bs, "\"(ao-type-atom) ").concat(_innerBs2, "\"").concat(desc).concat(_innerBs2, "\"").concat(bs, "\"");
35
- } else if (typeof value === "boolean") {
36
- var _innerBs3 = getBackslashes(level + 1);
37
- return "".concat(bs, "\"(ao-type-atom) ").concat(_innerBs3, "\"").concat(value).concat(_innerBs3, "\"").concat(bs, "\"");
38
- } else {
39
- return "".concat(bs, "\"").concat(String(value)).concat(bs, "\"");
40
- }
41
- }
42
-
43
- // Recursive function to handle arrays at any nesting level
44
- function encodeArrayAtLevel(items, level) {
45
- // The original code only goes 3 levels deep for arrays
46
- if (level >= 3) {
47
- var bs = getBackslashes(level);
48
- var stringItems = items.map(function (item) {
49
- if (typeof item === "number") {
50
- if (Number.isInteger(item)) {
51
- return "".concat(bs, "\"(ao-type-integer) ").concat(item).concat(bs, "\"");
52
- } else {
53
- return "".concat(bs, "\"(ao-type-float) ").concat((0, _encodeUtils.formatFloat)(item)).concat(bs, "\"");
54
- }
55
- } else if (typeof item === "string") {
56
- return "".concat(bs, "\"").concat(item).concat(bs, "\"");
57
- } else {
58
- return "".concat(bs, "\"").concat(String(item)).concat(bs, "\"");
59
- }
60
- }).join(", ");
61
- return "".concat(getBackslashes(level - 1), "\"(ao-type-list) ").concat(stringItems).concat(getBackslashes(level - 1), "\"");
62
- }
63
- var encodedItems = items.map(function (item) {
64
- if (Array.isArray(item)) {
65
- return encodeArrayAtLevel(item, level + 1);
66
- } else {
67
- return encodePrimitiveAtLevel(item, level);
68
- }
69
- }).join(", ");
70
- if (level === 0) {
71
- return "\"(ao-type-list) ".concat(encodedItems, "\"");
72
- } else {
73
- var _bs = getBackslashes(level - 1);
74
- return "".concat(_bs, "\"(ao-type-list) ").concat(encodedItems).concat(_bs, "\"");
75
- }
76
- }
77
- function encodeArrayItem(item) {
78
- if (typeof item === "number") {
79
- if (Number.isInteger(item)) {
80
- return "\"(ao-type-integer) ".concat(item, "\"");
81
- } else {
82
- return "\"(ao-type-float) ".concat((0, _encodeUtils.formatFloat)(item), "\"");
83
- }
84
- } else if (typeof item === "string") {
85
- return "\"".concat(item, "\"");
86
- } else if (item === null) {
87
- return "\"(ao-type-atom) \\\"null\\\"\"";
88
- } else if (item === undefined) {
89
- return "\"(ao-type-atom) \\\"undefined\\\"\"";
90
- } else if (_typeof(item) === "symbol") {
91
- var desc = item.description || "Symbol.for()";
92
- return "\"(ao-type-atom) \\\"".concat(desc, "\\\"\"");
93
- } else if (typeof item === "boolean") {
94
- return "\"(ao-type-atom) \\\"".concat(item, "\\\"\"");
95
- } else if (Array.isArray(item)) {
96
- return encodeArrayAtLevel(item, 1);
97
- } else if ((0, _encodeUtils.isBytes)(item)) {
98
- var buffer = (0, _encodeUtils.toBuffer)(item);
99
- if (buffer.length === 0 || buffer.byteLength === 0) {
100
- return "\"\"";
101
- }
102
- return "\"(ao-type-binary)\"";
103
- } else if ((0, _encodeUtils.isPojo)(item)) {
104
- var json = JSON.stringify(item);
105
- var escaped = json.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
106
- return "\"(ao-type-map) ".concat(escaped, "\"");
107
- } else {
108
- return "\"".concat(String(item), "\"");
109
- }
110
- }