wao 0.27.2 → 0.27.4
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/collect-body-keys.js +430 -0
- package/cjs/encode-array-item.js +110 -0
- package/cjs/encode-utils.js +241 -0
- package/cjs/encode.js +1183 -1541
- package/esm/collect-body-keys.js +401 -0
- package/esm/encode-array-item.js +112 -0
- package/esm/encode-utils.js +185 -0
- package/esm/encode.js +880 -1207
- package/package.json +1 -1
package/cjs/encode.js
CHANGED
|
@@ -5,14 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.enc = enc;
|
|
7
7
|
var _base64url = _interopRequireDefault(require("base64url"));
|
|
8
|
-
var
|
|
8
|
+
var _encodeUtils = require("./encode-utils.js");
|
|
9
|
+
var _encodeArrayItem = _interopRequireDefault(require("./encode-array-item.js"));
|
|
10
|
+
var _collectBodyKeys = _interopRequireDefault(require("./collect-body-keys.js"));
|
|
9
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
12
|
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
|
-
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
12
|
-
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."); }
|
|
13
|
-
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
14
|
-
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
15
13
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
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); }
|
|
16
15
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
17
16
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
17
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -21,1201 +20,1271 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
21
20
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
22
21
|
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); }
|
|
23
22
|
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); }); }; }
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
var MAX_HEADER_LENGTH = 4096;
|
|
24
|
+
|
|
25
|
+
// Step 1: Process and normalize input values (handle symbols, nested objects/arrays)
|
|
26
|
+
function processInputValues(obj) {
|
|
27
|
+
// Currently this is a no-op, but will be used for input validation/normalization
|
|
28
|
+
return obj;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
// Step 2: Handle empty object case
|
|
32
|
+
function handleEmptyObject(obj) {
|
|
33
|
+
if (Object.keys(obj).length === 0) {
|
|
34
|
+
return {
|
|
35
|
+
headers: {},
|
|
36
|
+
body: undefined
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
30
40
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
|
|
42
|
+
// Step 3: Handle single field with empty binary
|
|
43
|
+
function handleSingleEmptyBinaryField(obj) {
|
|
44
|
+
var objKeys = Object.keys(obj);
|
|
45
|
+
if (objKeys.length === 1) {
|
|
46
|
+
var fieldName = objKeys[0];
|
|
47
|
+
var fieldValue = obj[fieldName];
|
|
48
|
+
if ((0, _encodeUtils.isBytes)(fieldValue) && (fieldValue.length === 0 || fieldValue.byteLength === 0)) {
|
|
49
|
+
var headers = {};
|
|
50
|
+
headers["ao-types"] = "".concat(fieldName.toLowerCase(), "=\"empty-binary\"");
|
|
51
|
+
return {
|
|
52
|
+
headers: headers,
|
|
53
|
+
body: undefined
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
34
58
|
}
|
|
35
|
-
|
|
36
|
-
|
|
59
|
+
|
|
60
|
+
// Step 4: Handle single field with binary data
|
|
61
|
+
function handleSingleBinaryField(_x) {
|
|
62
|
+
return _handleSingleBinaryField.apply(this, arguments);
|
|
63
|
+
} // Step 5: Handle single field with primitive value (string/number/boolean/null/undefined/symbol)
|
|
64
|
+
function _handleSingleBinaryField() {
|
|
65
|
+
_handleSingleBinaryField = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(obj) {
|
|
66
|
+
var hasBodyBinary, otherFields, headers, bodyBuffer, bodyArrayBuffer, contentDigest, base64;
|
|
37
67
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
38
68
|
while (1) switch (_context.prev = _context.next) {
|
|
39
69
|
case 0:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (!(value instanceof Blob)) {
|
|
47
|
-
_context.next = 7;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
_context.next = 5;
|
|
51
|
-
return value.text();
|
|
52
|
-
case 5:
|
|
53
|
-
value = _context.sent;
|
|
54
|
-
return _context.abrupt("return", value.includes("\n"));
|
|
55
|
-
case 7:
|
|
56
|
-
if (!isBytes(value)) {
|
|
57
|
-
_context.next = 9;
|
|
70
|
+
hasBodyBinary = obj.body && (0, _encodeUtils.isBytes)(obj.body);
|
|
71
|
+
otherFields = Object.keys(obj).filter(function (k) {
|
|
72
|
+
return k !== "body";
|
|
73
|
+
});
|
|
74
|
+
if (!(hasBodyBinary && otherFields.length === 0)) {
|
|
75
|
+
_context.next = 12;
|
|
58
76
|
break;
|
|
59
77
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
headers = {};
|
|
79
|
+
bodyBuffer = (0, _encodeUtils.toBuffer)(obj.body);
|
|
80
|
+
bodyArrayBuffer = bodyBuffer.buffer.slice(bodyBuffer.byteOffset, bodyBuffer.byteOffset + bodyBuffer.byteLength);
|
|
81
|
+
_context.next = 8;
|
|
82
|
+
return (0, _encodeUtils.sha256)(bodyArrayBuffer);
|
|
83
|
+
case 8:
|
|
84
|
+
contentDigest = _context.sent;
|
|
85
|
+
base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
|
|
86
|
+
headers["content-digest"] = "sha-256=:".concat(base64, ":");
|
|
87
|
+
return _context.abrupt("return", {
|
|
88
|
+
headers: headers,
|
|
89
|
+
body: obj.body
|
|
90
|
+
});
|
|
91
|
+
case 12:
|
|
92
|
+
return _context.abrupt("return", null);
|
|
93
|
+
case 13:
|
|
64
94
|
case "end":
|
|
65
95
|
return _context.stop();
|
|
66
96
|
}
|
|
67
97
|
}, _callee);
|
|
68
98
|
}));
|
|
69
|
-
return
|
|
99
|
+
return _handleSingleBinaryField.apply(this, arguments);
|
|
70
100
|
}
|
|
71
|
-
function
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
var
|
|
101
|
+
function handleSinglePrimitiveField(_x2) {
|
|
102
|
+
return _handleSinglePrimitiveField.apply(this, arguments);
|
|
103
|
+
} // Step 6a: Handle single field with non-empty binary (not body field)
|
|
104
|
+
function _handleSinglePrimitiveField() {
|
|
105
|
+
_handleSinglePrimitiveField = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(obj) {
|
|
106
|
+
var objKeys, fieldName, fieldValue, headers, bodyContent, encoder, encoded, contentDigest, base64, aoType;
|
|
77
107
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
78
108
|
while (1) switch (_context2.prev = _context2.next) {
|
|
79
109
|
case 0:
|
|
80
|
-
|
|
81
|
-
|
|
110
|
+
objKeys = Object.keys(obj);
|
|
111
|
+
if (!(objKeys.length === 1)) {
|
|
112
|
+
_context2.next = 18;
|
|
82
113
|
break;
|
|
83
114
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (!(data instanceof Uint8Array)) {
|
|
89
|
-
_context2.next = 8;
|
|
115
|
+
fieldName = objKeys[0];
|
|
116
|
+
fieldValue = obj[fieldName];
|
|
117
|
+
if (!((fieldName === "data" || fieldName === "body") && (typeof fieldValue === "string" || typeof fieldValue === "boolean" || typeof fieldValue === "number" || fieldValue === null || fieldValue === undefined || _typeof(fieldValue) === "symbol"))) {
|
|
118
|
+
_context2.next = 18;
|
|
90
119
|
break;
|
|
91
120
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
121
|
+
headers = {};
|
|
122
|
+
bodyContent = (0, _encodeUtils.encodePrimitiveContent)(fieldValue);
|
|
123
|
+
encoder = new TextEncoder();
|
|
124
|
+
encoded = encoder.encode(bodyContent);
|
|
125
|
+
_context2.next = 11;
|
|
126
|
+
return (0, _encodeUtils.sha256)(encoded.buffer);
|
|
127
|
+
case 11:
|
|
128
|
+
contentDigest = _context2.sent;
|
|
129
|
+
base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
|
|
130
|
+
headers["content-digest"] = "sha-256=:".concat(base64, ":");
|
|
131
|
+
aoType = (0, _encodeUtils.getAoType)(fieldValue);
|
|
132
|
+
if (aoType === "atom" || aoType === "integer" || aoType === "float") {
|
|
133
|
+
headers["ao-types"] = "".concat(fieldName.toLowerCase(), "=\"").concat(aoType, "\"");
|
|
99
134
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
135
|
+
if (fieldName !== "body") {
|
|
136
|
+
headers["inline-body-key"] = fieldName;
|
|
137
|
+
}
|
|
138
|
+
return _context2.abrupt("return", {
|
|
139
|
+
headers: headers,
|
|
140
|
+
body: bodyContent
|
|
141
|
+
});
|
|
142
|
+
case 18:
|
|
143
|
+
return _context2.abrupt("return", null);
|
|
144
|
+
case 19:
|
|
109
145
|
case "end":
|
|
110
146
|
return _context2.stop();
|
|
111
147
|
}
|
|
112
148
|
}, _callee2);
|
|
113
149
|
}));
|
|
114
|
-
return
|
|
150
|
+
return _handleSinglePrimitiveField.apply(this, arguments);
|
|
151
|
+
}
|
|
152
|
+
function handleSingleNonEmptyBinaryField(_x3) {
|
|
153
|
+
return _handleSingleNonEmptyBinaryField.apply(this, arguments);
|
|
154
|
+
} // Step 6: Handle single field with non-ASCII string
|
|
155
|
+
function _handleSingleNonEmptyBinaryField() {
|
|
156
|
+
_handleSingleNonEmptyBinaryField = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(obj) {
|
|
157
|
+
var objKeys, fieldName, fieldValue, headers, bodyBuffer, bodyArrayBuffer, contentDigest, base64;
|
|
158
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
159
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
160
|
+
case 0:
|
|
161
|
+
objKeys = Object.keys(obj);
|
|
162
|
+
if (!(objKeys.length === 1)) {
|
|
163
|
+
_context3.next = 15;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
fieldName = objKeys[0];
|
|
167
|
+
fieldValue = obj[fieldName];
|
|
168
|
+
if (!((0, _encodeUtils.isBytes)(fieldValue) && fieldValue.length > 0)) {
|
|
169
|
+
_context3.next = 15;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
headers = {};
|
|
173
|
+
bodyBuffer = (0, _encodeUtils.toBuffer)(fieldValue);
|
|
174
|
+
bodyArrayBuffer = bodyBuffer.buffer.slice(bodyBuffer.byteOffset, bodyBuffer.byteOffset + bodyBuffer.byteLength);
|
|
175
|
+
_context3.next = 10;
|
|
176
|
+
return (0, _encodeUtils.sha256)(bodyArrayBuffer);
|
|
177
|
+
case 10:
|
|
178
|
+
contentDigest = _context3.sent;
|
|
179
|
+
base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
|
|
180
|
+
headers["content-digest"] = "sha-256=:".concat(base64, ":");
|
|
181
|
+
if (fieldName !== "body") {
|
|
182
|
+
headers["inline-body-key"] = fieldName;
|
|
183
|
+
}
|
|
184
|
+
return _context3.abrupt("return", {
|
|
185
|
+
headers: headers,
|
|
186
|
+
body: fieldValue
|
|
187
|
+
});
|
|
188
|
+
case 15:
|
|
189
|
+
return _context3.abrupt("return", null);
|
|
190
|
+
case 16:
|
|
191
|
+
case "end":
|
|
192
|
+
return _context3.stop();
|
|
193
|
+
}
|
|
194
|
+
}, _callee3);
|
|
195
|
+
}));
|
|
196
|
+
return _handleSingleNonEmptyBinaryField.apply(this, arguments);
|
|
115
197
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
198
|
+
function handleSingleNonAsciiStringField(_x4) {
|
|
199
|
+
return _handleSingleNonAsciiStringField.apply(this, arguments);
|
|
200
|
+
} // Step 7: Collect all keys that need to go in body
|
|
201
|
+
function _handleSingleNonAsciiStringField() {
|
|
202
|
+
_handleSingleNonAsciiStringField = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(obj) {
|
|
203
|
+
var objKeys, fieldName, fieldValue, headers, encoder, encoded, contentDigest, base64;
|
|
204
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
205
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
206
|
+
case 0:
|
|
207
|
+
objKeys = Object.keys(obj);
|
|
208
|
+
if (!(objKeys.length === 1)) {
|
|
209
|
+
_context4.next = 15;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
fieldName = objKeys[0];
|
|
213
|
+
fieldValue = obj[fieldName];
|
|
214
|
+
if (!(typeof fieldValue === "string" && (0, _encodeUtils.hasNonAscii)(fieldValue))) {
|
|
215
|
+
_context4.next = 15;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
headers = {};
|
|
219
|
+
encoder = new TextEncoder();
|
|
220
|
+
encoded = encoder.encode(fieldValue);
|
|
221
|
+
_context4.next = 10;
|
|
222
|
+
return (0, _encodeUtils.sha256)(encoded.buffer);
|
|
223
|
+
case 10:
|
|
224
|
+
contentDigest = _context4.sent;
|
|
225
|
+
base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
|
|
226
|
+
headers["content-digest"] = "sha-256=:".concat(base64, ":");
|
|
227
|
+
if (fieldName !== "body") {
|
|
228
|
+
headers["inline-body-key"] = fieldName;
|
|
229
|
+
}
|
|
230
|
+
return _context4.abrupt("return", {
|
|
231
|
+
headers: headers,
|
|
232
|
+
body: fieldValue
|
|
233
|
+
});
|
|
234
|
+
case 15:
|
|
235
|
+
return _context4.abrupt("return", null);
|
|
236
|
+
case 16:
|
|
237
|
+
case "end":
|
|
238
|
+
return _context4.stop();
|
|
239
|
+
}
|
|
240
|
+
}, _callee4);
|
|
241
|
+
}));
|
|
242
|
+
return _handleSingleNonAsciiStringField.apply(this, arguments);
|
|
121
243
|
}
|
|
122
|
-
function
|
|
123
|
-
return
|
|
244
|
+
function collectBodyKeysStep(obj) {
|
|
245
|
+
return (0, _collectBodyKeys["default"])(obj);
|
|
124
246
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
247
|
+
|
|
248
|
+
// Step 8: Process fields that can go in headers
|
|
249
|
+
function processHeaderFields(obj, bodyKeys, headers, headerTypes) {
|
|
250
|
+
var _loop = function _loop() {
|
|
251
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
252
|
+
key = _Object$entries$_i[0],
|
|
253
|
+
value = _Object$entries$_i[1];
|
|
254
|
+
var needsBody = bodyKeys.includes(key) || bodyKeys.some(function (k) {
|
|
255
|
+
return k.startsWith("".concat(key, "/"));
|
|
256
|
+
});
|
|
257
|
+
if (!needsBody) {
|
|
258
|
+
if (value === null) {
|
|
259
|
+
headers[key] = '"null"';
|
|
260
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
261
|
+
} else if (value === undefined) {
|
|
262
|
+
headers[key] = '"undefined"';
|
|
263
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
264
|
+
} else if (typeof value === "boolean") {
|
|
265
|
+
headers[key] = "\"".concat(value, "\"");
|
|
266
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
267
|
+
} else if (_typeof(value) === "symbol") {
|
|
268
|
+
headers[key] = "\"".concat(value.description || "Symbol.for()", "\"");
|
|
269
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
270
|
+
} else if (typeof value === "number") {
|
|
271
|
+
headers[key] = String(value);
|
|
272
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"").concat(Number.isInteger(value) ? "integer" : "float", "\""));
|
|
273
|
+
} else if (typeof value === "string") {
|
|
274
|
+
if (value.length === 0) {
|
|
275
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-binary\""));
|
|
276
|
+
} else if ((0, _encodeUtils.hasNonAscii)(value)) {
|
|
277
|
+
return 1; // continue
|
|
278
|
+
} else {
|
|
279
|
+
headers[key] = value;
|
|
280
|
+
}
|
|
281
|
+
} else if (Array.isArray(value) && value.length === 0) {
|
|
282
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-list\""));
|
|
283
|
+
} else if (Array.isArray(value) && !value.some(function (item) {
|
|
284
|
+
return (0, _encodeUtils.isPojo)(item);
|
|
285
|
+
})) {
|
|
286
|
+
var hasNonAsciiItems = value.some(function (item) {
|
|
287
|
+
return typeof item === "string" && (0, _encodeUtils.hasNonAscii)(item);
|
|
288
|
+
});
|
|
289
|
+
if (!hasNonAsciiItems) {
|
|
290
|
+
var encodedItems = value.map(function (item) {
|
|
291
|
+
return (0, _encodeArrayItem["default"])(item);
|
|
292
|
+
}).join(", ");
|
|
293
|
+
headers[key] = encodedItems;
|
|
294
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"list\""));
|
|
295
|
+
}
|
|
296
|
+
} else if ((0, _encodeUtils.isBytes)(value) && (value.length === 0 || value.byteLength === 0)) {
|
|
297
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-binary\""));
|
|
298
|
+
} else if ((0, _encodeUtils.isPojo)(value) && Object.keys(value).length === 0) {
|
|
299
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-message\""));
|
|
300
|
+
}
|
|
129
301
|
} else {
|
|
130
|
-
|
|
302
|
+
// Fields that need body still get type annotations
|
|
303
|
+
var aoType = (0, _encodeUtils.getAoType)(value);
|
|
304
|
+
if (aoType) {
|
|
305
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"").concat(aoType, "\""));
|
|
306
|
+
}
|
|
131
307
|
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
return "
|
|
148
|
-
}
|
|
149
|
-
|
|
308
|
+
};
|
|
309
|
+
for (var _i = 0, _Object$entries = Object.entries(obj); _i < _Object$entries.length; _i++) {
|
|
310
|
+
if (_loop()) continue;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Second pass for array type annotations
|
|
314
|
+
var _loop2 = function _loop2() {
|
|
315
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
316
|
+
key = _Object$entries2$_i[0],
|
|
317
|
+
value = _Object$entries2$_i[1];
|
|
318
|
+
if (Array.isArray(value)) {
|
|
319
|
+
if (bodyKeys.includes(key) || bodyKeys.some(function (k) {
|
|
320
|
+
return k.startsWith("".concat(key, "/"));
|
|
321
|
+
})) {
|
|
322
|
+
if (!headerTypes.some(function (t) {
|
|
323
|
+
return t.startsWith("".concat(key.toLowerCase(), "="));
|
|
324
|
+
})) {
|
|
325
|
+
headerTypes.push("".concat(key.toLowerCase(), "=\"list\""));
|
|
150
326
|
}
|
|
151
|
-
} else if (typeof nestedItem === "string") {
|
|
152
|
-
return "\\\"".concat(nestedItem, "\\\"");
|
|
153
|
-
} else if (nestedItem === null) {
|
|
154
|
-
return "\\\"(ao-type-atom) \\\\\\\"null\\\\\\\"\\\"";
|
|
155
|
-
} else if (nestedItem === undefined) {
|
|
156
|
-
return "\\\"(ao-type-atom) \\\\\\\"undefined\\\\\\\"\\\"";
|
|
157
|
-
} else if (_typeof(nestedItem) === "symbol") {
|
|
158
|
-
var _desc = nestedItem.description || "Symbol.for()";
|
|
159
|
-
return "\\\"(ao-type-atom) \\\\\\\"".concat(_desc, "\\\\\\\"\\\"");
|
|
160
|
-
} else if (typeof nestedItem === "boolean") {
|
|
161
|
-
return "\\\"(ao-type-atom) \\\\\\\"".concat(nestedItem, "\\\\\\\"\\\"");
|
|
162
|
-
} else if (Array.isArray(nestedItem)) {
|
|
163
|
-
// Handle nested arrays recursively
|
|
164
|
-
var deeperItems = nestedItem.map(function (deepItem) {
|
|
165
|
-
if (typeof deepItem === "number") {
|
|
166
|
-
if (Number.isInteger(deepItem)) {
|
|
167
|
-
return "\\\\\\\"(ao-type-integer) ".concat(deepItem, "\\\\\\\"");
|
|
168
|
-
} else {
|
|
169
|
-
return "\\\\\\\"(ao-type-float) ".concat(formatFloat(deepItem), "\\\\\\\"");
|
|
170
|
-
}
|
|
171
|
-
} else if (typeof deepItem === "string") {
|
|
172
|
-
return "\\\\\\\"".concat(deepItem, "\\\\\\\"");
|
|
173
|
-
} else if (Array.isArray(deepItem)) {
|
|
174
|
-
// Even deeper nesting - need to escape more
|
|
175
|
-
var deepestItems = deepItem.map(function (deepestItem) {
|
|
176
|
-
if (typeof deepestItem === "number") {
|
|
177
|
-
if (Number.isInteger(deepestItem)) {
|
|
178
|
-
return "\\\\\\\\\\\\\\\"(ao-type-integer) ".concat(deepestItem, "\\\\\\\\\\\\\\\"");
|
|
179
|
-
} else {
|
|
180
|
-
return "\\\\\\\\\\\\\\\"(ao-type-float) ".concat(formatFloat(deepestItem), "\\\\\\\\\\\\\\\"");
|
|
181
|
-
}
|
|
182
|
-
} else if (typeof deepestItem === "string") {
|
|
183
|
-
return "\\\\\\\\\\\\\\\"".concat(deepestItem, "\\\\\\\\\\\\\\\"");
|
|
184
|
-
} else {
|
|
185
|
-
return "\\\\\\\\\\\\\\\"".concat(String(deepestItem), "\\\\\\\\\\\\\\\"");
|
|
186
|
-
}
|
|
187
|
-
}).join(", ");
|
|
188
|
-
return "\\\\\\\"(ao-type-list) ".concat(deepestItems, "\\\\\\\"");
|
|
189
|
-
} else if (deepItem === null) {
|
|
190
|
-
return "\\\\\\\"(ao-type-atom) \\\\\\\\\\\\\\\"null\\\\\\\\\\\\\\\"\\\\\\\"";
|
|
191
|
-
} else if (deepItem === undefined) {
|
|
192
|
-
return "\\\\\\\"(ao-type-atom) \\\\\\\\\\\\\\\"undefined\\\\\\\\\\\\\\\"\\\\\\\"";
|
|
193
|
-
} else if (_typeof(deepItem) === "symbol") {
|
|
194
|
-
var _desc2 = deepItem.description || "Symbol.for()";
|
|
195
|
-
return "\\\\\\\"(ao-type-atom) \\\\\\\\\\\\\\\"".concat(_desc2, "\\\\\\\\\\\\\\\"\\\\\\\"");
|
|
196
|
-
} else if (typeof deepItem === "boolean") {
|
|
197
|
-
return "\\\\\\\"(ao-type-atom) \\\\\\\\\\\\\\\"".concat(deepItem, "\\\\\\\\\\\\\\\"\\\\\\\"");
|
|
198
|
-
} else {
|
|
199
|
-
return "\\\\\\\"".concat(String(deepItem), "\\\\\\\"");
|
|
200
|
-
}
|
|
201
|
-
}).join(", ");
|
|
202
|
-
return "\\\"(ao-type-list) ".concat(deeperItems, "\\\"");
|
|
203
|
-
} else {
|
|
204
|
-
return "\\\"".concat(String(nestedItem), "\\\"");
|
|
205
327
|
}
|
|
206
|
-
}).join(", ");
|
|
207
|
-
return "\"(ao-type-list) ".concat(nestedItems, "\"");
|
|
208
|
-
} else if (isBytes(item)) {
|
|
209
|
-
var buffer = toBuffer(item);
|
|
210
|
-
if (buffer.length === 0 || buffer.byteLength === 0) {
|
|
211
|
-
return "\"\"";
|
|
212
328
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
var escaped = json.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
217
|
-
return "\"(ao-type-map) ".concat(escaped, "\"");
|
|
218
|
-
} else {
|
|
219
|
-
return "\"".concat(String(item), "\"");
|
|
329
|
+
};
|
|
330
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(obj); _i2 < _Object$entries2.length; _i2++) {
|
|
331
|
+
_loop2();
|
|
220
332
|
}
|
|
221
333
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
334
|
+
|
|
335
|
+
// Step 9: Handle case where all body keys are empty binaries
|
|
336
|
+
function handleAllEmptyBinaryBodyKeys(obj, bodyKeys, headers, headerTypes) {
|
|
337
|
+
if (bodyKeys.length === 0) {
|
|
338
|
+
if (headerTypes.length > 0) {
|
|
339
|
+
headers["ao-types"] = headerTypes.sort().join(", ");
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
headers: headers,
|
|
343
|
+
body: undefined
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
var allBodyKeysAreEmptyBinaries = bodyKeys.every(function (key) {
|
|
347
|
+
var value = (0, _encodeUtils.getValueByPath)(obj, key);
|
|
348
|
+
return (0, _encodeUtils.isBytes)(value) && (value.length === 0 || value.byteLength === 0);
|
|
349
|
+
});
|
|
350
|
+
if (allBodyKeysAreEmptyBinaries) {
|
|
351
|
+
if (headerTypes.length > 0) {
|
|
352
|
+
headers["ao-types"] = headerTypes.sort().join(", ");
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
headers: headers,
|
|
356
|
+
body: undefined
|
|
357
|
+
};
|
|
231
358
|
}
|
|
359
|
+
return null;
|
|
232
360
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (value.length === 0) {
|
|
257
|
-
console.log("[traverse] Empty array at ".concat(fullPath, " - marking parent as having simple fields"));
|
|
258
|
-
hasSimpleFields = true;
|
|
259
|
-
} else if (hasObjects) {
|
|
260
|
-
hasArraysWithObjects = true;
|
|
261
|
-
// Check if we need special handling for mixed arrays
|
|
262
|
-
var hasEmptyStrings = value.some(function (item) {
|
|
263
|
-
return typeof item === "string" && item === "";
|
|
264
|
-
});
|
|
265
|
-
var hasEmptyObjects = value.some(function (item) {
|
|
266
|
-
return isPojo(item) && Object.keys(item).length === 0;
|
|
361
|
+
|
|
362
|
+
// Step 10: Handle single body key optimization
|
|
363
|
+
function handleSingleBodyKeyOptimization(_x5, _x6, _x7, _x8) {
|
|
364
|
+
return _handleSingleBodyKeyOptimization.apply(this, arguments);
|
|
365
|
+
} // Step 11: Sort body keys
|
|
366
|
+
function _handleSingleBodyKeyOptimization() {
|
|
367
|
+
_handleSingleBodyKeyOptimization = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(obj, bodyKeys, headers, headerTypes) {
|
|
368
|
+
var singleKey, value, otherFieldsAreEmpty, bodyBuffer, bodyArrayBuffer, contentDigest, base64;
|
|
369
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
370
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
371
|
+
case 0:
|
|
372
|
+
if (!(bodyKeys.length === 1)) {
|
|
373
|
+
_context5.next = 15;
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
singleKey = bodyKeys[0];
|
|
377
|
+
value = (0, _encodeUtils.getValueByPath)(obj, singleKey);
|
|
378
|
+
otherFieldsAreEmpty = Object.entries(obj).every(function (_ref11) {
|
|
379
|
+
var _ref12 = _slicedToArray(_ref11, 2),
|
|
380
|
+
key = _ref12[0],
|
|
381
|
+
val = _ref12[1];
|
|
382
|
+
if (key === singleKey) return true;
|
|
383
|
+
return (0, _encodeUtils.isEmpty)(val);
|
|
267
384
|
});
|
|
268
|
-
|
|
269
|
-
|
|
385
|
+
if (!(otherFieldsAreEmpty && (0, _encodeUtils.isBytes)(value) && value.length > 0)) {
|
|
386
|
+
_context5.next = 15;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
bodyBuffer = (0, _encodeUtils.toBuffer)(value);
|
|
390
|
+
bodyArrayBuffer = bodyBuffer.buffer.slice(bodyBuffer.byteOffset, bodyBuffer.byteOffset + bodyBuffer.byteLength);
|
|
391
|
+
_context5.next = 9;
|
|
392
|
+
return (0, _encodeUtils.sha256)(bodyArrayBuffer);
|
|
393
|
+
case 9:
|
|
394
|
+
contentDigest = _context5.sent;
|
|
395
|
+
base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
|
|
396
|
+
headers["content-digest"] = "sha-256=:".concat(base64, ":");
|
|
397
|
+
if (singleKey !== "body") {
|
|
398
|
+
headers["inline-body-key"] = singleKey;
|
|
399
|
+
}
|
|
400
|
+
if (headerTypes.length > 0) {
|
|
401
|
+
headers["ao-types"] = headerTypes.sort().join(", ");
|
|
402
|
+
}
|
|
403
|
+
return _context5.abrupt("return", {
|
|
404
|
+
headers: headers,
|
|
405
|
+
body: value
|
|
270
406
|
});
|
|
407
|
+
case 15:
|
|
408
|
+
return _context5.abrupt("return", null);
|
|
409
|
+
case 16:
|
|
410
|
+
case "end":
|
|
411
|
+
return _context5.stop();
|
|
412
|
+
}
|
|
413
|
+
}, _callee5);
|
|
414
|
+
}));
|
|
415
|
+
return _handleSingleBodyKeyOptimization.apply(this, arguments);
|
|
416
|
+
}
|
|
417
|
+
function sortBodyKeys(bodyKeys) {
|
|
418
|
+
return bodyKeys.sort(function (a, b) {
|
|
419
|
+
var aIsArrayElement = /\/\d+$/.test(a);
|
|
420
|
+
var bIsArrayElement = /\/\d+$/.test(b);
|
|
421
|
+
var aBase = a.split("/")[0];
|
|
422
|
+
var bBase = b.split("/")[0];
|
|
423
|
+
if (aBase === bBase) {
|
|
424
|
+
if (!aIsArrayElement && bIsArrayElement) {
|
|
425
|
+
return -1;
|
|
426
|
+
}
|
|
427
|
+
if (aIsArrayElement && !bIsArrayElement) {
|
|
428
|
+
return 1;
|
|
429
|
+
}
|
|
430
|
+
if (aIsArrayElement && bIsArrayElement) {
|
|
431
|
+
var aIndex = parseInt(a.split("/")[1]);
|
|
432
|
+
var bIndex = parseInt(b.split("/")[1]);
|
|
433
|
+
return aIndex - bIndex;
|
|
434
|
+
}
|
|
435
|
+
return a.localeCompare(b);
|
|
436
|
+
}
|
|
437
|
+
return a.localeCompare(b);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
271
440
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
441
|
+
// Step 12: Check for special data/body case
|
|
442
|
+
function checkSpecialDataBodyCase(obj, sortedBodyKeys) {
|
|
443
|
+
return sortedBodyKeys.includes("data") && sortedBodyKeys.includes("body") && obj.data && obj.data.body && (0, _encodeUtils.isBytes)(obj.data.body) && obj.body && obj.body.data && (0, _encodeUtils.isBytes)(obj.body.data);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// Step 13.2.2: Handle empty string in nested path
|
|
447
|
+
function handleEmptyStringInNestedPath(bodyKey, value, pathParts) {
|
|
448
|
+
if (typeof value === "string" && value === "" && pathParts.length > 1) {
|
|
449
|
+
var lines = [];
|
|
450
|
+
lines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
451
|
+
lines.push("");
|
|
452
|
+
lines.push("");
|
|
453
|
+
return new Blob([lines.join("\r\n")]);
|
|
454
|
+
}
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
279
457
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
458
|
+
// Step 13.2.3.2: Handle arrays with only empty elements
|
|
459
|
+
function handleArrayWithOnlyEmptyElements(bodyKey, value, headers, sortedBodyKeys) {
|
|
460
|
+
var fieldLines = [];
|
|
461
|
+
var partTypes = [];
|
|
462
|
+
value.forEach(function (item, idx) {
|
|
463
|
+
var index = idx + 1;
|
|
464
|
+
var itemType = (0, _encodeUtils.getAoType)(item);
|
|
465
|
+
if (itemType) {
|
|
466
|
+
partTypes.push("".concat(index, "=\"").concat(itemType, "\""));
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
var isInline = bodyKey === "body" && headers["inline-body-key"] === "body";
|
|
470
|
+
if (isInline) {
|
|
471
|
+
var orderedLines = [];
|
|
472
|
+
if (partTypes.length > 0) {
|
|
473
|
+
orderedLines.push("ao-types: ".concat((0, _encodeUtils.sortTypeAnnotations)(partTypes).join(", ")));
|
|
474
|
+
}
|
|
475
|
+
orderedLines.push("content-disposition: inline");
|
|
476
|
+
orderedLines.push("");
|
|
477
|
+
return new Blob([orderedLines.join("\r\n")]);
|
|
478
|
+
} else {
|
|
479
|
+
var _orderedLines = [];
|
|
480
|
+
if (partTypes.length > 0) {
|
|
481
|
+
_orderedLines.push("ao-types: ".concat((0, _encodeUtils.sortTypeAnnotations)(partTypes).join(", ")));
|
|
482
|
+
}
|
|
483
|
+
_orderedLines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
484
|
+
var isLastBodyPart = sortedBodyKeys.indexOf(bodyKey) === sortedBodyKeys.length - 1;
|
|
485
|
+
var hasOnlyTypes = partTypes.length > 0 && fieldLines.length === 0;
|
|
486
|
+
if (isLastBodyPart && hasOnlyTypes) {
|
|
487
|
+
return new Blob([_orderedLines.join("\r\n")]);
|
|
488
|
+
} else {
|
|
489
|
+
_orderedLines.push("");
|
|
490
|
+
return new Blob([_orderedLines.join("\r\n")]);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Step 13.2.3.3: Build indices with own parts
|
|
496
|
+
function buildIndicesWithOwnParts(bodyKey, sortedBodyKeys) {
|
|
497
|
+
var indicesWithOwnParts = new Set();
|
|
498
|
+
sortedBodyKeys.forEach(function (key) {
|
|
499
|
+
if (key.startsWith(bodyKey + "/")) {
|
|
500
|
+
var subPath = key.substring(bodyKey.length + 1);
|
|
501
|
+
var match = subPath.match(/^(\d+)/);
|
|
502
|
+
if (match) {
|
|
503
|
+
indicesWithOwnParts.add(parseInt(match[1]));
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
return indicesWithOwnParts;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Step 13.2.3.4: Process array items
|
|
511
|
+
function processArrayItems(value, indicesWithOwnParts, hasNestedObjectParts, pathParts) {
|
|
512
|
+
var fieldLines = [];
|
|
513
|
+
var partTypes = [];
|
|
514
|
+
if (hasNestedObjectParts) {
|
|
515
|
+
value.forEach(function (item, idx) {
|
|
516
|
+
var index = idx + 1;
|
|
517
|
+
if (Array.isArray(item)) {
|
|
518
|
+
partTypes.push("".concat(index, "=\"list\""));
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
value.forEach(function (item, idx) {
|
|
523
|
+
var index = idx + 1;
|
|
524
|
+
if (indicesWithOwnParts.has(index)) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if (hasNestedObjectParts && Array.isArray(item) && item.some(function (subItem) {
|
|
528
|
+
return (0, _encodeUtils.isPojo)(subItem);
|
|
529
|
+
})) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
if (typeof item === "string" && item === "") {
|
|
533
|
+
partTypes.push("".concat(index, "=\"empty-binary\""));
|
|
534
|
+
} else if ((0, _encodeUtils.isPojo)(item) && Object.keys(item).length === 0) {
|
|
535
|
+
partTypes.push("".concat(index, "=\"empty-message\""));
|
|
536
|
+
} else if ((0, _encodeUtils.isPojo)(item)) {
|
|
537
|
+
// Non-empty objects are handled elsewhere
|
|
538
|
+
} else if (Array.isArray(item)) {
|
|
539
|
+
if (item.length === 0) {
|
|
540
|
+
partTypes.push("".concat(index, "=\"empty-list\""));
|
|
541
|
+
} else {
|
|
542
|
+
partTypes.push("".concat(index, "=\"list\""));
|
|
543
|
+
var encodedItems = item.map(function (subItem) {
|
|
544
|
+
if (typeof subItem === "number") {
|
|
545
|
+
if (Number.isInteger(subItem)) {
|
|
546
|
+
return "\"(ao-type-integer) ".concat(subItem, "\"");
|
|
547
|
+
} else {
|
|
548
|
+
return "\"(ao-type-float) ".concat((0, _encodeUtils.formatFloat)(subItem), "\"");
|
|
293
549
|
}
|
|
294
|
-
} else if (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
} else {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (Object.keys(item).length > 0) {
|
|
312
|
-
nestedPaths.push(itemPath);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
if (hasNonObjects) {
|
|
317
|
-
hasSimpleFields = true;
|
|
318
|
-
keys.push(fullPath);
|
|
550
|
+
} else if (typeof subItem === "string") {
|
|
551
|
+
return "\"".concat(subItem, "\"");
|
|
552
|
+
} else if (subItem === null) {
|
|
553
|
+
return "\"(ao-type-atom) \\\"null\\\"\"";
|
|
554
|
+
} else if (subItem === undefined) {
|
|
555
|
+
return "\"(ao-type-atom) \\\"undefined\\\"\"";
|
|
556
|
+
} else if (_typeof(subItem) === "symbol") {
|
|
557
|
+
var desc = subItem.description || "Symbol.for()";
|
|
558
|
+
return "\"(ao-type-atom) \\\"".concat(desc, "\\\"\"");
|
|
559
|
+
} else if (typeof subItem === "boolean") {
|
|
560
|
+
return "\"(ao-type-atom) \\\"".concat(subItem, "\\\"\"");
|
|
561
|
+
} else if (Array.isArray(subItem)) {
|
|
562
|
+
return (0, _encodeArrayItem["default"])(subItem);
|
|
563
|
+
} else if ((0, _encodeUtils.isBytes)(subItem)) {
|
|
564
|
+
var buffer = (0, _encodeUtils.toBuffer)(subItem);
|
|
565
|
+
if (buffer.length === 0 || buffer.byteLength === 0) {
|
|
566
|
+
return "\"\"";
|
|
319
567
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
} else if (isPojo(value)) {
|
|
326
|
-
if (Object.keys(value).length === 0) {
|
|
327
|
-
console.log("[traverse] Empty object at ".concat(fullPath, " - marking parent as having simple fields"));
|
|
328
|
-
hasSimpleFields = true;
|
|
329
|
-
} else {
|
|
330
|
-
// Don't traverse into the object if it only contains empty values
|
|
331
|
-
var containsOnlyEmptyCollections = Object.entries(value).every(function (_ref) {
|
|
332
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
333
|
-
k = _ref2[0],
|
|
334
|
-
v = _ref2[1];
|
|
335
|
-
return Array.isArray(v) && v.length === 0 || isPojo(v) && Object.keys(v).length === 0 || isBytes(v) && (v.length === 0 || v.byteLength === 0) || typeof v === "string" && v.length === 0;
|
|
336
|
-
});
|
|
337
|
-
if (containsOnlyEmptyCollections && Object.keys(value).length > 0) {
|
|
338
|
-
console.log("[traverse] Object at ".concat(fullPath, " contains only empty collections - adding as body key"));
|
|
339
|
-
keys.push(fullPath);
|
|
568
|
+
return "\"(ao-type-binary)\"";
|
|
569
|
+
} else if ((0, _encodeUtils.isPojo)(subItem)) {
|
|
570
|
+
var json = JSON.stringify(subItem);
|
|
571
|
+
var escaped = json.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
572
|
+
return "\"(ao-type-map) ".concat(escaped, "\"");
|
|
340
573
|
} else {
|
|
341
|
-
|
|
342
|
-
var hasArraysWithOnlyEmptyElements = Object.entries(value).some(function (_ref3) {
|
|
343
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
344
|
-
k = _ref4[0],
|
|
345
|
-
v = _ref4[1];
|
|
346
|
-
return Array.isArray(v) && v.length > 0 && v.every(function (item) {
|
|
347
|
-
return Array.isArray(item) && item.length === 0 || isPojo(item) && Object.keys(item).length === 0 || typeof item === "string" && item === "";
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
if (hasArraysWithOnlyEmptyElements) {
|
|
351
|
-
// This object needs a body part to show its array types
|
|
352
|
-
console.log("[traverse] Object at ".concat(fullPath, " has arrays with empty elements - adding as body key"));
|
|
353
|
-
keys.push(fullPath);
|
|
354
|
-
}
|
|
355
|
-
console.log("[traverse] Non-empty object at ".concat(fullPath, " - will traverse into it"));
|
|
356
|
-
nestedPaths.push(fullPath);
|
|
574
|
+
return "\"".concat(String(subItem), "\"");
|
|
357
575
|
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
576
|
+
}).join(", ");
|
|
577
|
+
fieldLines.push("".concat(index, ": ").concat(encodedItems));
|
|
578
|
+
}
|
|
579
|
+
} else if (typeof item === "number") {
|
|
580
|
+
if (Number.isInteger(item)) {
|
|
581
|
+
partTypes.push("".concat(index, "=\"integer\""));
|
|
582
|
+
fieldLines.push("".concat(index, ": ").concat(item));
|
|
583
|
+
} else {
|
|
584
|
+
partTypes.push("".concat(index, "=\"float\""));
|
|
585
|
+
fieldLines.push("".concat(index, ": ").concat((0, _encodeUtils.formatFloat)(item)));
|
|
586
|
+
}
|
|
587
|
+
} else if (typeof item === "string") {
|
|
588
|
+
fieldLines.push("".concat(index, ": ").concat(item));
|
|
589
|
+
} else if (item === null || item === undefined || _typeof(item) === "symbol" || typeof item === "boolean") {
|
|
590
|
+
partTypes.push("".concat(index, "=\"atom\""));
|
|
591
|
+
if (item === null) {
|
|
592
|
+
fieldLines.push("".concat(index, ": null"));
|
|
593
|
+
} else if (item === undefined) {
|
|
594
|
+
fieldLines.push("".concat(index, ": undefined"));
|
|
595
|
+
} else if (_typeof(item) === "symbol") {
|
|
596
|
+
var desc = item.description || "Symbol.for()";
|
|
597
|
+
fieldLines.push("".concat(index, ": ").concat(desc));
|
|
598
|
+
} else {
|
|
599
|
+
fieldLines.push("".concat(index, ": ").concat(item));
|
|
600
|
+
}
|
|
601
|
+
} else if ((0, _encodeUtils.isBytes)(item)) {
|
|
602
|
+
var buffer = (0, _encodeUtils.toBuffer)(item);
|
|
603
|
+
if (buffer.length === 0) {
|
|
604
|
+
partTypes.push("".concat(index, "=\"empty-binary\""));
|
|
605
|
+
} else {
|
|
606
|
+
partTypes.push("".concat(index, "=\"binary\""));
|
|
366
607
|
}
|
|
367
|
-
};
|
|
368
|
-
for (var _i = 0, _Object$entries = Object.entries(current); _i < _Object$entries.length; _i++) {
|
|
369
|
-
_loop();
|
|
370
|
-
}
|
|
371
|
-
if (hasSimpleFields) {
|
|
372
|
-
console.log("[traverse] Adding \"".concat(path, "\" to keys (has simple fields)"));
|
|
373
|
-
keys.push(path);
|
|
374
|
-
} else if (hasArraysWithObjects && path) {
|
|
375
|
-
// If the object only contains arrays with objects, we still need to add it as a body key
|
|
376
|
-
console.log("[traverse] Adding \"".concat(path, "\" to keys (contains arrays with objects)"));
|
|
377
|
-
keys.push(path);
|
|
378
608
|
}
|
|
609
|
+
});
|
|
610
|
+
return {
|
|
611
|
+
fieldLines: fieldLines,
|
|
612
|
+
partTypes: partTypes
|
|
613
|
+
};
|
|
614
|
+
}
|
|
379
615
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
var hasOnlyEmptyElements = value.every(function (item) {
|
|
388
|
-
return Array.isArray(item) && item.length === 0 || isPojo(item) && Object.keys(item).length === 0 || typeof item === "string" && item === "";
|
|
389
|
-
});
|
|
390
|
-
if (hasOnlyEmptyElements) {
|
|
391
|
-
console.log("[traverse] Array at ".concat(fullPath, " has only empty elements - adding as body key"));
|
|
392
|
-
keys.push(fullPath);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
616
|
+
// Step 13.2.3.5: Create array body part
|
|
617
|
+
function createArrayBodyPart(bodyKey, fieldLines, partTypes, headers) {
|
|
618
|
+
var isInline = bodyKey === "body" && headers["inline-body-key"] === "body";
|
|
619
|
+
if (isInline) {
|
|
620
|
+
var orderedLines = [];
|
|
621
|
+
if (partTypes.length > 0) {
|
|
622
|
+
orderedLines.push("ao-types: ".concat((0, _encodeUtils.sortTypeAnnotations)(partTypes).join(", ")));
|
|
395
623
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
var
|
|
400
|
-
var _iterator = _createForOfIteratorHelper(parts),
|
|
624
|
+
orderedLines.push("content-disposition: inline");
|
|
625
|
+
if (fieldLines.length > 0) {
|
|
626
|
+
orderedLines.push("");
|
|
627
|
+
var _iterator = _createForOfIteratorHelper(fieldLines),
|
|
401
628
|
_step;
|
|
402
629
|
try {
|
|
403
630
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
404
|
-
var
|
|
405
|
-
|
|
406
|
-
nestedObj = nestedObj[parseInt(part) - 1];
|
|
407
|
-
} else {
|
|
408
|
-
nestedObj = nestedObj[part];
|
|
409
|
-
}
|
|
631
|
+
var line = _step.value;
|
|
632
|
+
orderedLines.push(line);
|
|
410
633
|
}
|
|
411
634
|
} catch (err) {
|
|
412
635
|
_iterator.e(err);
|
|
413
636
|
} finally {
|
|
414
637
|
_iterator.f();
|
|
415
638
|
}
|
|
416
|
-
|
|
417
|
-
|
|
639
|
+
}
|
|
640
|
+
return new Blob([orderedLines.join("\r\n") + "\r\n"]);
|
|
641
|
+
} else {
|
|
642
|
+
var _orderedLines2 = [];
|
|
643
|
+
if (partTypes.length > 0) {
|
|
644
|
+
_orderedLines2.push("ao-types: ".concat((0, _encodeUtils.sortTypeAnnotations)(partTypes).join(", ")));
|
|
645
|
+
}
|
|
646
|
+
_orderedLines2.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
647
|
+
var _iterator2 = _createForOfIteratorHelper(fieldLines),
|
|
648
|
+
_step2;
|
|
649
|
+
try {
|
|
650
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
651
|
+
var _line = _step2.value;
|
|
652
|
+
_orderedLines2.push(_line);
|
|
418
653
|
}
|
|
654
|
+
} catch (err) {
|
|
655
|
+
_iterator2.e(err);
|
|
656
|
+
} finally {
|
|
657
|
+
_iterator2.f();
|
|
658
|
+
}
|
|
659
|
+
if (fieldLines.length > 0) {
|
|
660
|
+
return new Blob([_orderedLines2.join("\r\n") + "\r\n"]);
|
|
661
|
+
} else {
|
|
662
|
+
return new Blob([_orderedLines2.join("\r\n")]);
|
|
419
663
|
}
|
|
420
664
|
}
|
|
421
|
-
|
|
422
|
-
var _loop2 = function _loop2() {
|
|
423
|
-
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i4], 2),
|
|
424
|
-
key = _Object$entries3$_i[0],
|
|
425
|
-
value = _Object$entries3$_i[1];
|
|
426
|
-
console.log("\n[main loop] Processing key: \"".concat(key, "\""));
|
|
427
|
-
console.log("[main loop] Value type: ".concat(Array.isArray(value) ? "array" : _typeof(value)));
|
|
428
|
-
console.log("[main loop] Array length: ".concat(Array.isArray(value) ? value.length : "N/A"));
|
|
429
|
-
if ((key === "data" || key === "body") && (typeof value === "string" || typeof value === "boolean" || typeof value === "number" || value === null || value === undefined || _typeof(value) === "symbol") && objKeys.length > 1) {
|
|
430
|
-
// Special handling: only add to body keys if there's no other data/body field with an object
|
|
431
|
-
if (key === "data" && obj.body && isPojo(obj.body) && Object.keys(obj.body).length > 0) {
|
|
432
|
-
console.log("[main loop] Skipping special data field");
|
|
433
|
-
} else if (key === "body" && obj.data && isPojo(obj.data) && Object.keys(obj.data).length > 0) {
|
|
434
|
-
console.log("[main loop] Skipping special body field");
|
|
435
|
-
} else {
|
|
436
|
-
console.log("[main loop] Adding special data/body key: \"".concat(key, "\""));
|
|
437
|
-
keys.push(key);
|
|
438
|
-
}
|
|
439
|
-
} else if (Array.isArray(value)) {
|
|
440
|
-
if (value.length === 0) {
|
|
441
|
-
console.log("[main loop] SKIPPING empty array for key: \"".concat(key, "\""));
|
|
442
|
-
return 1; // continue
|
|
443
|
-
}
|
|
444
|
-
var hasObjects = value.some(function (item) {
|
|
445
|
-
return isPojo(item);
|
|
446
|
-
});
|
|
447
|
-
var hasArrays = value.some(function (item) {
|
|
448
|
-
return Array.isArray(item);
|
|
449
|
-
});
|
|
450
|
-
var hasNonObjects = value.some(function (item) {
|
|
451
|
-
return !isPojo(item);
|
|
452
|
-
});
|
|
665
|
+
}
|
|
453
666
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
667
|
+
// Step 13.2.3: Handle array values
|
|
668
|
+
function handleArrayValue(bodyKey, value, headers, sortedBodyKeys, pathParts) {
|
|
669
|
+
var arrayInfo = (0, _encodeUtils.analyzeArray)(value);
|
|
670
|
+
if (arrayInfo.hasOnlyNonEmptyObjects) {
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
if (arrayInfo.hasOnlyEmptyElements) {
|
|
674
|
+
return handleArrayWithOnlyEmptyElements(bodyKey, value, headers, sortedBodyKeys);
|
|
675
|
+
}
|
|
676
|
+
var indicesWithOwnParts = buildIndicesWithOwnParts(bodyKey, sortedBodyKeys);
|
|
677
|
+
var hasNestedObjectParts = sortedBodyKeys.some(function (key) {
|
|
678
|
+
return key.startsWith(bodyKey + "/") && key.split("/").length > pathParts.length + 1;
|
|
679
|
+
});
|
|
680
|
+
var _processArrayItems = processArrayItems(value, indicesWithOwnParts, hasNestedObjectParts, pathParts),
|
|
681
|
+
fieldLines = _processArrayItems.fieldLines,
|
|
682
|
+
partTypes = _processArrayItems.partTypes;
|
|
683
|
+
return createArrayBodyPart(bodyKey, fieldLines, partTypes, headers);
|
|
684
|
+
}
|
|
463
685
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
});
|
|
686
|
+
// Step 13.2.4.3: Process object fields
|
|
687
|
+
function processObjectFields(value, bodyKey, sortedBodyKeys) {
|
|
688
|
+
var objectTypes = [];
|
|
689
|
+
var fieldLines = [];
|
|
690
|
+
var binaryFields = [];
|
|
691
|
+
var arrayTypes = [];
|
|
471
692
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
value.forEach(function (item, index) {
|
|
482
|
-
if (Array.isArray(item)) {
|
|
483
|
-
item.forEach(function (subItem, subIndex) {
|
|
484
|
-
if (isPojo(subItem)) {
|
|
485
|
-
var path = "".concat(key, "/").concat(index + 1, "/").concat(subIndex + 1);
|
|
486
|
-
console.log("[main loop] Adding nested object path: \"".concat(path, "\""));
|
|
487
|
-
keys.push(path);
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
bodyPartCounter++;
|
|
492
|
-
});
|
|
493
|
-
// Always add the main array key
|
|
494
|
-
console.log("[main loop] ADDING main array key: \"".concat(key, "\""));
|
|
495
|
-
keys.push(key);
|
|
496
|
-
} else if (hasObjects && (hasEmptyStrings || hasEmptyObjects) && !hasObjectsWithOnlyEmptyValues) {
|
|
497
|
-
// Special handling: only non-empty objects get parts
|
|
498
|
-
value.forEach(function (item, index) {
|
|
499
|
-
if (isPojo(item) && Object.keys(item).length > 0) {
|
|
500
|
-
var path = "".concat(key, "/").concat(bodyPartCounter);
|
|
501
|
-
console.log("[main loop] Adding non-empty object path: \"".concat(path, "\" (array index ").concat(index, ")"));
|
|
502
|
-
keys.push(path);
|
|
503
|
-
// Add paths for nested objects
|
|
504
|
-
for (var _i5 = 0, _Object$entries4 = Object.entries(item); _i5 < _Object$entries4.length; _i5++) {
|
|
505
|
-
var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i5], 2),
|
|
506
|
-
nestedKey = _Object$entries4$_i[0],
|
|
507
|
-
nestedValue = _Object$entries4$_i[1];
|
|
508
|
-
if (isPojo(nestedValue)) {
|
|
509
|
-
var nestedPath = "".concat(key, "/").concat(bodyPartCounter, "/").concat(nestedKey);
|
|
510
|
-
console.log("[main loop] Adding nested object path: \"".concat(nestedPath, "\""));
|
|
511
|
-
keys.push(nestedPath);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
bodyPartCounter++;
|
|
516
|
-
});
|
|
517
|
-
// Always add the main array key
|
|
518
|
-
console.log("[main loop] ADDING main array key: \"".concat(key, "\""));
|
|
519
|
-
keys.push(key);
|
|
520
|
-
} else if (hasObjects) {
|
|
521
|
-
// Normal handling: all objects get parts (except if parent array has only empty elements)
|
|
522
|
-
var skipEmptyObjects = false;
|
|
693
|
+
// First collect array types
|
|
694
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(value); _i3 < _Object$entries3.length; _i3++) {
|
|
695
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
696
|
+
k = _Object$entries3$_i[0],
|
|
697
|
+
v = _Object$entries3$_i[1];
|
|
698
|
+
if (Array.isArray(v)) {
|
|
699
|
+
arrayTypes.push("".concat(k.toLowerCase(), "=\"").concat(v.length === 0 ? "empty-list" : "list", "\""));
|
|
700
|
+
}
|
|
701
|
+
}
|
|
523
702
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
});
|
|
562
|
-
// Don't add main array key for arrays with only objects containing empty values
|
|
563
|
-
if (!hasObjectsWithOnlyEmptyValues || value.some(function (item) {
|
|
564
|
-
return !isPojo(item);
|
|
565
|
-
})) {
|
|
566
|
-
// Check if array has only empty elements
|
|
567
|
-
var hasOnlyEmptyElements = value.every(function (item) {
|
|
568
|
-
return Array.isArray(item) && item.length === 0 || isPojo(item) && Object.keys(item).length === 0 || typeof item === "string" && item === "";
|
|
569
|
-
});
|
|
570
|
-
if (!hasOnlyEmptyElements) {
|
|
571
|
-
// Always add the main array key
|
|
572
|
-
console.log("[main loop] ADDING main array key: \"".concat(key, "\""));
|
|
573
|
-
keys.push(key);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
} else {
|
|
577
|
-
// Check if array has only empty elements
|
|
578
|
-
var hasOnlyEmptyArraysOrObjects = value.every(function (item) {
|
|
579
|
-
return Array.isArray(item) && item.length === 0 || isPojo(item) && Object.keys(item).length === 0 || typeof item === "string" && item === "";
|
|
580
|
-
});
|
|
581
|
-
if (hasOnlyEmptyArraysOrObjects && value.length > 0) {
|
|
582
|
-
// Always add the main array key for arrays with only empty elements
|
|
583
|
-
console.log("[main loop] ADDING main array key for empty elements: \"".concat(key, "\""));
|
|
584
|
-
keys.push(key);
|
|
585
|
-
} else if (!hasOnlyEmptyArraysOrObjects) {
|
|
586
|
-
// Always add the main array key
|
|
587
|
-
console.log("[main loop] ADDING main array key: \"".concat(key, "\""));
|
|
588
|
-
keys.push(key);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
703
|
+
// Then process other fields
|
|
704
|
+
for (var _i4 = 0, _Object$entries4 = Object.entries(value); _i4 < _Object$entries4.length; _i4++) {
|
|
705
|
+
var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
|
|
706
|
+
_k = _Object$entries4$_i[0],
|
|
707
|
+
_v = _Object$entries4$_i[1];
|
|
708
|
+
var childPath = "".concat(bodyKey, "/").concat(_k);
|
|
709
|
+
if (sortedBodyKeys.includes(childPath)) {
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
if (Array.isArray(_v) && _v.some(function (item) {
|
|
713
|
+
return (0, _encodeUtils.isPojo)(item);
|
|
714
|
+
})) {
|
|
715
|
+
var hasOnlyEmpty = _v.every(function (item) {
|
|
716
|
+
return (0, _encodeUtils.isEmpty)(item);
|
|
717
|
+
});
|
|
718
|
+
if (hasOnlyEmpty) {
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
if (Array.isArray(_v)) {
|
|
723
|
+
// Type already added in arrayTypes
|
|
724
|
+
} else if (_v === null || _v === undefined || _typeof(_v) === "symbol" || typeof _v === "boolean") {
|
|
725
|
+
objectTypes.push("".concat(_k.toLowerCase(), "=\"atom\""));
|
|
726
|
+
} else if (typeof _v === "number") {
|
|
727
|
+
objectTypes.push("".concat(_k.toLowerCase(), "=\"").concat(Number.isInteger(_v) ? "integer" : "float", "\""));
|
|
728
|
+
} else if (typeof _v === "string" && _v.length === 0) {
|
|
729
|
+
objectTypes.push("".concat(_k.toLowerCase(), "=\"empty-binary\""));
|
|
730
|
+
} else if ((0, _encodeUtils.isBytes)(_v) && (_v.length === 0 || _v.byteLength === 0)) {
|
|
731
|
+
objectTypes.push("".concat(_k.toLowerCase(), "=\"empty-binary\""));
|
|
732
|
+
} else if ((0, _encodeUtils.isPojo)(_v) && Object.keys(_v).length === 0) {
|
|
733
|
+
objectTypes.push("".concat(_k.toLowerCase(), "=\"empty-message\""));
|
|
734
|
+
}
|
|
735
|
+
if (typeof _v === "string") {
|
|
736
|
+
if (_v.length === 0) {
|
|
737
|
+
fieldLines.push("".concat(_k, ": "));
|
|
738
|
+
} else {
|
|
739
|
+
fieldLines.push("".concat(_k, ": ").concat(_v));
|
|
591
740
|
}
|
|
592
|
-
} else if (
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
} else if (
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
741
|
+
} else if (typeof _v === "number") {
|
|
742
|
+
fieldLines.push("".concat(_k, ": ").concat(_v));
|
|
743
|
+
} else if (typeof _v === "boolean") {
|
|
744
|
+
fieldLines.push("".concat(_k, ": \"").concat(_v, "\""));
|
|
745
|
+
} else if (_v === null) {
|
|
746
|
+
fieldLines.push("".concat(_k, ": \"null\""));
|
|
747
|
+
} else if (_v === undefined) {
|
|
748
|
+
fieldLines.push("".concat(_k, ": \"undefined\""));
|
|
749
|
+
} else if (_typeof(_v) === "symbol") {
|
|
750
|
+
var desc = _v.description || "Symbol.for()";
|
|
751
|
+
fieldLines.push("".concat(_k, ": \"").concat(desc, "\""));
|
|
752
|
+
} else if ((0, _encodeUtils.isBytes)(_v)) {
|
|
753
|
+
var buffer = (0, _encodeUtils.toBuffer)(_v);
|
|
754
|
+
binaryFields.push({
|
|
755
|
+
key: _k,
|
|
756
|
+
buffer: buffer
|
|
757
|
+
});
|
|
758
|
+
} else if (Array.isArray(_v) && _v.length > 0) {
|
|
759
|
+
var _childPath = "".concat(bodyKey, "/").concat(_k);
|
|
760
|
+
if (!sortedBodyKeys.includes(_childPath)) {
|
|
761
|
+
var hasObjects = _v.some(function (item) {
|
|
762
|
+
return (0, _encodeUtils.isPojo)(item);
|
|
763
|
+
});
|
|
764
|
+
if (!hasObjects) {
|
|
765
|
+
var encodedItems = _v.map(function (item) {
|
|
766
|
+
return (0, _encodeArrayItem["default"])(item);
|
|
767
|
+
}).join(", ");
|
|
768
|
+
fieldLines.push("".concat(_k, ": ").concat(encodedItems));
|
|
769
|
+
}
|
|
601
770
|
}
|
|
602
|
-
} else if (typeof value === "string" && value.includes("\n")) {
|
|
603
|
-
console.log("[main loop] Adding key for string with newline: \"".concat(key, "\""));
|
|
604
|
-
keys.push(key);
|
|
605
|
-
} else if (typeof value === "string" && hasNonAscii(value)) {
|
|
606
|
-
console.log("[main loop] Adding key for non-ASCII string: \"".concat(key, "\""));
|
|
607
|
-
keys.push(key);
|
|
608
|
-
} else {
|
|
609
|
-
console.log("[main loop] Skipping key: \"".concat(key, "\" (no match)"));
|
|
610
771
|
}
|
|
611
|
-
};
|
|
612
|
-
for (var _i4 = 0, _Object$entries3 = Object.entries(obj); _i4 < _Object$entries3.length; _i4++) {
|
|
613
|
-
if (_loop2()) continue;
|
|
614
772
|
}
|
|
615
|
-
var
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
var arrayPath = parts.slice(0, -1).join("/");
|
|
623
|
-
var arrayValue = obj;
|
|
773
|
+
var allTypes = [].concat(arrayTypes, objectTypes);
|
|
774
|
+
return {
|
|
775
|
+
allTypes: allTypes,
|
|
776
|
+
fieldLines: fieldLines,
|
|
777
|
+
binaryFields: binaryFields
|
|
778
|
+
};
|
|
779
|
+
}
|
|
624
780
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
781
|
+
// Step 13.2.4.5: Create object body part
|
|
782
|
+
function createObjectBodyPart(bodyKey, value, allTypes, fieldLines, binaryFields, headers, sortedBodyKeys) {
|
|
783
|
+
var isInline = bodyKey === "body" && headers["inline-body-key"] === "body";
|
|
784
|
+
var lines = [];
|
|
785
|
+
if (isInline) {
|
|
786
|
+
lines.push("content-disposition: inline");
|
|
787
|
+
} else {
|
|
788
|
+
lines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
789
|
+
}
|
|
790
|
+
if (isInline) {
|
|
791
|
+
var orderedLines = [];
|
|
792
|
+
var _iterator3 = _createForOfIteratorHelper(fieldLines),
|
|
793
|
+
_step3;
|
|
794
|
+
try {
|
|
795
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
796
|
+
var line = _step3.value;
|
|
797
|
+
orderedLines.push(line);
|
|
798
|
+
}
|
|
799
|
+
} catch (err) {
|
|
800
|
+
_iterator3.e(err);
|
|
801
|
+
} finally {
|
|
802
|
+
_iterator3.f();
|
|
803
|
+
}
|
|
804
|
+
if (allTypes.length > 0) {
|
|
805
|
+
orderedLines.push("ao-types: ".concat(allTypes.sort().join(", ")));
|
|
806
|
+
}
|
|
807
|
+
orderedLines.push("content-disposition: inline");
|
|
808
|
+
var binaryFieldsForInline = Object.entries(value).filter(function (_ref) {
|
|
809
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
810
|
+
k = _ref2[0],
|
|
811
|
+
v = _ref2[1];
|
|
812
|
+
return (0, _encodeUtils.isBytes)(v) && !sortedBodyKeys.includes("".concat(bodyKey, "/").concat(k));
|
|
813
|
+
}).map(function (_ref3) {
|
|
814
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
815
|
+
k = _ref4[0],
|
|
816
|
+
v = _ref4[1];
|
|
817
|
+
return {
|
|
818
|
+
key: k,
|
|
819
|
+
buffer: (0, _encodeUtils.toBuffer)(v)
|
|
820
|
+
};
|
|
821
|
+
});
|
|
822
|
+
if (binaryFieldsForInline.length > 0) {
|
|
823
|
+
var parts = [];
|
|
824
|
+
parts.push(Buffer.from(orderedLines.join("\r\n")));
|
|
825
|
+
var _iterator4 = _createForOfIteratorHelper(binaryFieldsForInline),
|
|
826
|
+
_step4;
|
|
628
827
|
try {
|
|
629
|
-
for (
|
|
630
|
-
var
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
828
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
829
|
+
var _step4$value = _step4.value,
|
|
830
|
+
key = _step4$value.key,
|
|
831
|
+
buffer = _step4$value.buffer;
|
|
832
|
+
parts.push(Buffer.from("\r\n".concat(key, ": ")));
|
|
833
|
+
parts.push(buffer);
|
|
636
834
|
}
|
|
637
|
-
|
|
638
|
-
// Check if this array contains only empty elements
|
|
639
835
|
} catch (err) {
|
|
640
|
-
|
|
836
|
+
_iterator4.e(err);
|
|
641
837
|
} finally {
|
|
642
|
-
|
|
838
|
+
_iterator4.f();
|
|
643
839
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
840
|
+
parts.push(Buffer.from("\r\n"));
|
|
841
|
+
var fullBody = Buffer.concat(parts);
|
|
842
|
+
return new Blob([fullBody]);
|
|
843
|
+
} else {
|
|
844
|
+
var isLastBodyPart = sortedBodyKeys.indexOf(bodyKey) === sortedBodyKeys.length - 1;
|
|
845
|
+
var hasOnlyTypes = allTypes.length > 0 && fieldLines.length === 0;
|
|
846
|
+
if (isLastBodyPart && hasOnlyTypes) {
|
|
847
|
+
return new Blob([orderedLines.join("\r\n")]);
|
|
848
|
+
} else if (fieldLines.length === 0) {
|
|
849
|
+
return new Blob([orderedLines.join("\r\n")]);
|
|
850
|
+
} else {
|
|
851
|
+
return new Blob([orderedLines.join("\r\n") + "\r\n"]);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
} else {
|
|
855
|
+
var _orderedLines3 = [];
|
|
856
|
+
if (allTypes.length > 0) {
|
|
857
|
+
_orderedLines3.push("ao-types: ".concat(allTypes.sort().join(", ")));
|
|
858
|
+
}
|
|
859
|
+
_orderedLines3.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
860
|
+
var hasBinaryFields = binaryFields && binaryFields.length > 0;
|
|
861
|
+
if (hasBinaryFields || fieldLines.length === 0) {
|
|
862
|
+
_orderedLines3.push("");
|
|
863
|
+
}
|
|
864
|
+
var _iterator5 = _createForOfIteratorHelper(fieldLines),
|
|
865
|
+
_step5;
|
|
866
|
+
try {
|
|
867
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
868
|
+
var _line2 = _step5.value;
|
|
869
|
+
_orderedLines3.push(_line2);
|
|
870
|
+
}
|
|
871
|
+
} catch (err) {
|
|
872
|
+
_iterator5.e(err);
|
|
873
|
+
} finally {
|
|
874
|
+
_iterator5.f();
|
|
875
|
+
}
|
|
876
|
+
if (binaryFields && binaryFields.length > 0) {
|
|
877
|
+
var _parts = [];
|
|
878
|
+
var headerText = _orderedLines3.join("\r\n");
|
|
879
|
+
_parts.push(Buffer.from(headerText));
|
|
880
|
+
for (var i = 0; i < binaryFields.length; i++) {
|
|
881
|
+
var _binaryFields$i = binaryFields[i],
|
|
882
|
+
_key = _binaryFields$i.key,
|
|
883
|
+
_buffer = _binaryFields$i.buffer;
|
|
884
|
+
if (i > 0) {
|
|
885
|
+
_parts.push(Buffer.from("\r\n"));
|
|
652
886
|
}
|
|
887
|
+
_parts.push(Buffer.from("".concat(_key, ": ")));
|
|
888
|
+
_parts.push(_buffer);
|
|
889
|
+
}
|
|
890
|
+
_parts.push(Buffer.from("\r\n"));
|
|
891
|
+
var _fullBody = Buffer.concat(_parts);
|
|
892
|
+
return new Blob([_fullBody]);
|
|
893
|
+
} else {
|
|
894
|
+
if (fieldLines.length > 0) {
|
|
895
|
+
return new Blob([_orderedLines3.join("\r\n") + "\r\n"]);
|
|
896
|
+
} else {
|
|
897
|
+
return new Blob([_orderedLines3.join("\r\n")]);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// Step 13.2.4: Handle object values
|
|
904
|
+
function handleObjectValue(obj, bodyKey, value, headers, sortedBodyKeys, pathParts, hasSpecialDataBody) {
|
|
905
|
+
if (Object.keys(value).length === 0) {
|
|
906
|
+
// Skip empty objects in certain contexts
|
|
907
|
+
var parentPath = pathParts.slice(0, -1).join("/");
|
|
908
|
+
var parentValue = parentPath ? (0, _encodeUtils.getValueByPath)(obj, parentPath) : obj;
|
|
909
|
+
if (Array.isArray(parentValue)) {
|
|
910
|
+
var parentArrayInfo = (0, _encodeUtils.analyzeArray)(parentValue);
|
|
911
|
+
if (parentArrayInfo.hasObjects && (parentArrayInfo.hasEmptyStrings || parentArrayInfo.hasEmptyObjects)) {
|
|
912
|
+
return null;
|
|
653
913
|
}
|
|
654
914
|
}
|
|
655
|
-
return
|
|
915
|
+
return null;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// Skip special data/body case
|
|
919
|
+
if (hasSpecialDataBody && bodyKey === "data" && Object.keys(value).length === 1 && value.body && (0, _encodeUtils.isBytes)(value.body)) {
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
var _processObjectFields = processObjectFields(value, bodyKey, sortedBodyKeys),
|
|
923
|
+
allTypes = _processObjectFields.allTypes,
|
|
924
|
+
fieldLines = _processObjectFields.fieldLines,
|
|
925
|
+
binaryFields = _processObjectFields.binaryFields;
|
|
926
|
+
|
|
927
|
+
// Check if object should be skipped
|
|
928
|
+
var hasOnlyEmptyCollections = Object.entries(value).every(function (_ref5) {
|
|
929
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
930
|
+
k = _ref6[0],
|
|
931
|
+
v = _ref6[1];
|
|
932
|
+
return (0, _encodeUtils.isEmpty)(v);
|
|
656
933
|
});
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
934
|
+
var hasArraysWithOnlyEmptyElements = Object.entries(value).some(function (_ref7) {
|
|
935
|
+
var _ref8 = _slicedToArray(_ref7, 2),
|
|
936
|
+
k = _ref8[0],
|
|
937
|
+
v = _ref8[1];
|
|
938
|
+
return Array.isArray(v) && v.length > 0 && v.every(function (item) {
|
|
939
|
+
return (0, _encodeUtils.isEmpty)(item);
|
|
940
|
+
});
|
|
941
|
+
});
|
|
942
|
+
var shouldSkipObject = Object.entries(value).every(function (_ref9) {
|
|
943
|
+
var _ref10 = _slicedToArray(_ref9, 2),
|
|
944
|
+
k = _ref10[0],
|
|
945
|
+
v = _ref10[1];
|
|
946
|
+
var childPath = "".concat(bodyKey, "/").concat(k);
|
|
947
|
+
if (sortedBodyKeys.includes(childPath)) return true;
|
|
948
|
+
if (Array.isArray(v) && v.some(function (item) {
|
|
949
|
+
return (0, _encodeUtils.isPojo)(item);
|
|
950
|
+
})) {
|
|
951
|
+
var hasOnlyEmpty = v.every(function (item) {
|
|
952
|
+
return (0, _encodeUtils.isEmpty)(item);
|
|
953
|
+
});
|
|
954
|
+
return hasOnlyEmpty || sortedBodyKeys.includes(childPath);
|
|
955
|
+
}
|
|
956
|
+
return false;
|
|
957
|
+
});
|
|
958
|
+
if (shouldSkipObject && !hasOnlyEmptyCollections && !hasArraysWithOnlyEmptyElements) {
|
|
959
|
+
return null;
|
|
960
|
+
}
|
|
961
|
+
return createObjectBodyPart(bodyKey, value, allTypes, fieldLines, binaryFields, headers, sortedBodyKeys);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// Step 13.2.5: Handle primitive values
|
|
965
|
+
function handlePrimitiveValue(bodyKey, value, headers) {
|
|
966
|
+
var isInline = bodyKey === "body" && headers["inline-body-key"] === "body";
|
|
967
|
+
var lines = [];
|
|
968
|
+
if (isInline) {
|
|
969
|
+
lines.push("content-disposition: inline");
|
|
970
|
+
} else {
|
|
971
|
+
lines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
972
|
+
}
|
|
973
|
+
if (typeof value === "string") {
|
|
974
|
+
lines.push("");
|
|
975
|
+
lines.push(value);
|
|
976
|
+
return new Blob([lines.join("\r\n")]);
|
|
977
|
+
} else {
|
|
978
|
+
var content = (0, _encodeUtils.encodePrimitiveContent)(value);
|
|
979
|
+
lines.push("");
|
|
980
|
+
lines.push(content);
|
|
981
|
+
return new Blob([lines.join("\r\n")]);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// Step 13.2.6: Handle binary values
|
|
986
|
+
function handleBinaryValue(bodyKey, value, headers) {
|
|
987
|
+
var isInline = bodyKey === "body" && headers["inline-body-key"] === "body";
|
|
988
|
+
var lines = [];
|
|
989
|
+
if (isInline) {
|
|
990
|
+
lines.push("content-disposition: inline");
|
|
991
|
+
} else {
|
|
992
|
+
lines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
993
|
+
}
|
|
994
|
+
var buffer = (0, _encodeUtils.toBuffer)(value);
|
|
995
|
+
var headerText = lines.join("\r\n") + "\r\n\r\n";
|
|
996
|
+
return new Blob([headerText, buffer]);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// Step 13.3: Handle special data/body case
|
|
1000
|
+
function handleSpecialDataBodyCase(obj, hasSpecialDataBody) {
|
|
1001
|
+
if (hasSpecialDataBody && obj.data && obj.data.body && (0, _encodeUtils.isBytes)(obj.data.body)) {
|
|
1002
|
+
var buffer = (0, _encodeUtils.toBuffer)(obj.data.body);
|
|
1003
|
+
var specialPart = ["content-disposition: form-data;name=\"data/body\"", "", ""].join("\r\n");
|
|
1004
|
+
return new Blob([specialPart, buffer]);
|
|
1005
|
+
}
|
|
1006
|
+
return null;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// Step 13: Build body parts for each body key
|
|
1010
|
+
function buildBodyParts(obj, sortedBodyKeys, headers, hasSpecialDataBody) {
|
|
1011
|
+
// Step 13.1: Initialize body parts collection
|
|
1012
|
+
var bodyParts = [];
|
|
1013
|
+
|
|
1014
|
+
// Step 13.2: Process each body key
|
|
1015
|
+
var _iterator6 = _createForOfIteratorHelper(sortedBodyKeys),
|
|
1016
|
+
_step6;
|
|
1017
|
+
try {
|
|
1018
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1019
|
+
var bodyKey = _step6.value;
|
|
1020
|
+
// Step 13.2.1: Get value for current body key
|
|
1021
|
+
var value = (0, _encodeUtils.getValueByPath)(obj, bodyKey);
|
|
1022
|
+
var pathParts = bodyKey.split("/");
|
|
1023
|
+
|
|
1024
|
+
// Step 13.2.2: Handle empty string in nested path
|
|
1025
|
+
var emptyStringPart = handleEmptyStringInNestedPath(bodyKey, value, pathParts);
|
|
1026
|
+
if (emptyStringPart) {
|
|
1027
|
+
bodyParts.push(emptyStringPart);
|
|
1028
|
+
continue;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// Step 13.2.3: Handle array values
|
|
1032
|
+
if (Array.isArray(value)) {
|
|
1033
|
+
var arrayPart = handleArrayValue(bodyKey, value, headers, sortedBodyKeys, pathParts);
|
|
1034
|
+
if (arrayPart) {
|
|
1035
|
+
bodyParts.push(arrayPart);
|
|
1036
|
+
}
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// Step 13.2.4: Handle object values
|
|
1041
|
+
if ((0, _encodeUtils.isPojo)(value)) {
|
|
1042
|
+
var objectPart = handleObjectValue(obj, bodyKey, value, headers, sortedBodyKeys, pathParts, hasSpecialDataBody);
|
|
1043
|
+
if (objectPart) {
|
|
1044
|
+
bodyParts.push(objectPart);
|
|
1045
|
+
}
|
|
1046
|
+
continue;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// Step 13.2.5: Handle primitive values
|
|
1050
|
+
if (typeof value === "string" || typeof value === "boolean" || typeof value === "number" || value === null || value === undefined || _typeof(value) === "symbol") {
|
|
1051
|
+
var primitivePart = handlePrimitiveValue(bodyKey, value, headers);
|
|
1052
|
+
bodyParts.push(primitivePart);
|
|
1053
|
+
continue;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
// Step 13.2.6: Handle binary values
|
|
1057
|
+
if ((0, _encodeUtils.isBytes)(value)) {
|
|
1058
|
+
var binaryPart = handleBinaryValue(bodyKey, value, headers);
|
|
1059
|
+
bodyParts.push(binaryPart);
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// Step 13.3: Handle special data/body case
|
|
1065
|
+
} catch (err) {
|
|
1066
|
+
_iterator6.e(err);
|
|
1067
|
+
} finally {
|
|
1068
|
+
_iterator6.f();
|
|
1069
|
+
}
|
|
1070
|
+
var specialPart = handleSpecialDataBodyCase(obj, hasSpecialDataBody);
|
|
1071
|
+
if (specialPart) {
|
|
1072
|
+
bodyParts.push(specialPart);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// Step 13.4: Return body parts
|
|
1076
|
+
return bodyParts;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// Step 14: Generate multipart boundary
|
|
1080
|
+
function generateBoundary(_x9) {
|
|
1081
|
+
return _generateBoundary.apply(this, arguments);
|
|
1082
|
+
} // Step 15: Assemble final multipart body
|
|
1083
|
+
function _generateBoundary() {
|
|
1084
|
+
_generateBoundary = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(bodyParts) {
|
|
1085
|
+
var partsContent, allContent, boundaryHash, boundary;
|
|
1086
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
1087
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
1088
|
+
case 0:
|
|
1089
|
+
_context6.next = 2;
|
|
1090
|
+
return Promise.all(bodyParts.map(function (part) {
|
|
1091
|
+
return part.text();
|
|
1092
|
+
}));
|
|
1093
|
+
case 2:
|
|
1094
|
+
partsContent = _context6.sent;
|
|
1095
|
+
allContent = partsContent.join("");
|
|
1096
|
+
_context6.next = 6;
|
|
1097
|
+
return (0, _encodeUtils.sha256)(new TextEncoder().encode(allContent));
|
|
1098
|
+
case 6:
|
|
1099
|
+
boundaryHash = _context6.sent;
|
|
1100
|
+
boundary = _base64url["default"].encode(Buffer.from(boundaryHash));
|
|
1101
|
+
return _context6.abrupt("return", boundary);
|
|
1102
|
+
case 9:
|
|
1103
|
+
case "end":
|
|
1104
|
+
return _context6.stop();
|
|
1105
|
+
}
|
|
1106
|
+
}, _callee6);
|
|
1107
|
+
}));
|
|
1108
|
+
return _generateBoundary.apply(this, arguments);
|
|
1109
|
+
}
|
|
1110
|
+
function assembleMultipartBody(bodyParts, boundary) {
|
|
1111
|
+
var finalParts = [];
|
|
1112
|
+
for (var i = 0; i < bodyParts.length; i++) {
|
|
1113
|
+
if (i === 0) {
|
|
1114
|
+
finalParts.push(new Blob(["--".concat(boundary, "\r\n")]));
|
|
1115
|
+
} else {
|
|
1116
|
+
finalParts.push(new Blob(["\r\n--".concat(boundary, "\r\n")]));
|
|
1117
|
+
}
|
|
1118
|
+
finalParts.push(bodyParts[i]);
|
|
1119
|
+
}
|
|
1120
|
+
finalParts.push(new Blob(["\r\n--".concat(boundary, "--")]));
|
|
1121
|
+
return new Blob(finalParts);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// Step 16: Calculate content digest
|
|
1125
|
+
function calculateContentDigest(_x10) {
|
|
1126
|
+
return _calculateContentDigest.apply(this, arguments);
|
|
1127
|
+
} // Step 17: Set final headers (content-type, content-length)
|
|
1128
|
+
function _calculateContentDigest() {
|
|
1129
|
+
_calculateContentDigest = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(body) {
|
|
1130
|
+
var finalContent, contentDigest, base64;
|
|
1131
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
1132
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
1133
|
+
case 0:
|
|
1134
|
+
_context7.next = 2;
|
|
1135
|
+
return body.arrayBuffer();
|
|
1136
|
+
case 2:
|
|
1137
|
+
finalContent = _context7.sent;
|
|
1138
|
+
if (!(finalContent.byteLength > 0)) {
|
|
1139
|
+
_context7.next = 9;
|
|
1140
|
+
break;
|
|
1141
|
+
}
|
|
1142
|
+
_context7.next = 6;
|
|
1143
|
+
return (0, _encodeUtils.sha256)(finalContent);
|
|
1144
|
+
case 6:
|
|
1145
|
+
contentDigest = _context7.sent;
|
|
1146
|
+
base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
|
|
1147
|
+
return _context7.abrupt("return", {
|
|
1148
|
+
digest: base64,
|
|
1149
|
+
byteLength: finalContent.byteLength
|
|
1150
|
+
});
|
|
1151
|
+
case 9:
|
|
1152
|
+
return _context7.abrupt("return", {
|
|
1153
|
+
digest: null,
|
|
1154
|
+
byteLength: finalContent.byteLength
|
|
1155
|
+
});
|
|
1156
|
+
case 10:
|
|
1157
|
+
case "end":
|
|
1158
|
+
return _context7.stop();
|
|
1159
|
+
}
|
|
1160
|
+
}, _callee7);
|
|
1161
|
+
}));
|
|
1162
|
+
return _calculateContentDigest.apply(this, arguments);
|
|
1163
|
+
}
|
|
1164
|
+
function setFinalHeaders(headers, boundary, contentDigest, byteLength) {
|
|
1165
|
+
headers["content-type"] = "multipart/form-data; boundary=\"".concat(boundary, "\"");
|
|
1166
|
+
if (contentDigest) {
|
|
1167
|
+
headers["content-digest"] = "sha-256=:".concat(contentDigest, ":");
|
|
1168
|
+
}
|
|
1169
|
+
headers["content-length"] = String(byteLength);
|
|
661
1170
|
}
|
|
662
1171
|
function encode() {
|
|
663
1172
|
return _encode.apply(this, arguments);
|
|
664
1173
|
}
|
|
665
1174
|
function _encode() {
|
|
666
|
-
_encode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1175
|
+
_encode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
667
1176
|
var obj,
|
|
668
|
-
_processValue,
|
|
669
1177
|
processedObj,
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
fieldName,
|
|
677
|
-
fieldValue,
|
|
678
|
-
_headers,
|
|
679
|
-
hasBodyBinary,
|
|
680
|
-
otherFields,
|
|
681
|
-
_headers2,
|
|
682
|
-
bodyBuffer,
|
|
683
|
-
bodyArrayBuffer,
|
|
684
|
-
contentDigest,
|
|
685
|
-
base64,
|
|
686
|
-
_fieldName,
|
|
687
|
-
_fieldValue,
|
|
688
|
-
_headers3,
|
|
689
|
-
_bodyBuffer,
|
|
690
|
-
_bodyArrayBuffer,
|
|
691
|
-
_contentDigest,
|
|
692
|
-
_base,
|
|
693
|
-
_headers4,
|
|
694
|
-
bodyContent,
|
|
695
|
-
encoder,
|
|
696
|
-
encoded,
|
|
697
|
-
_contentDigest2,
|
|
698
|
-
_base2,
|
|
699
|
-
_headers5,
|
|
700
|
-
_encoder,
|
|
701
|
-
_encoded,
|
|
702
|
-
_contentDigest3,
|
|
703
|
-
_base3,
|
|
1178
|
+
emptyResult,
|
|
1179
|
+
emptyBinaryResult,
|
|
1180
|
+
singleBinaryResult,
|
|
1181
|
+
primitiveResult,
|
|
1182
|
+
nonEmptyBinaryResult,
|
|
1183
|
+
nonAsciiResult,
|
|
704
1184
|
bodyKeys,
|
|
1185
|
+
objKeys,
|
|
705
1186
|
headers,
|
|
706
1187
|
headerTypes,
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
_Object$entries8,
|
|
710
|
-
_loop4,
|
|
711
|
-
_i10,
|
|
712
|
-
_Object$entries9,
|
|
713
|
-
allBodyKeysAreEmptyBinaries,
|
|
714
|
-
singleKey,
|
|
715
|
-
pathParts,
|
|
716
|
-
value,
|
|
717
|
-
_iterator4,
|
|
718
|
-
_step4,
|
|
719
|
-
part,
|
|
720
|
-
otherFieldsAreEmpty,
|
|
721
|
-
_bodyBuffer2,
|
|
722
|
-
_bodyArrayBuffer2,
|
|
723
|
-
_contentDigest4,
|
|
724
|
-
_base4,
|
|
1188
|
+
emptyBinaryBodyResult,
|
|
1189
|
+
singleBodyKeyResult,
|
|
725
1190
|
sortedBodyKeys,
|
|
726
1191
|
hasSpecialDataBody,
|
|
727
1192
|
bodyParts,
|
|
728
|
-
_iterator5,
|
|
729
|
-
_step5,
|
|
730
|
-
_loop5,
|
|
731
|
-
_ret,
|
|
732
|
-
buffer,
|
|
733
|
-
specialPart,
|
|
734
|
-
partsContent,
|
|
735
|
-
allContent,
|
|
736
|
-
boundaryHash,
|
|
737
1193
|
boundary,
|
|
738
|
-
finalParts,
|
|
739
|
-
i,
|
|
740
1194
|
body,
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
return _regeneratorRuntime().wrap(function
|
|
746
|
-
while (1) switch (
|
|
1195
|
+
_yield$calculateConte,
|
|
1196
|
+
contentDigest,
|
|
1197
|
+
byteLength,
|
|
1198
|
+
_args8 = arguments;
|
|
1199
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1200
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
747
1201
|
case 0:
|
|
748
|
-
obj =
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
return value.map(_processValue);
|
|
756
|
-
} else if (isPojo(value)) {
|
|
757
|
-
var result = {};
|
|
758
|
-
for (var _i7 = 0, _Object$entries6 = Object.entries(value); _i7 < _Object$entries6.length; _i7++) {
|
|
759
|
-
var _Object$entries6$_i = _slicedToArray(_Object$entries6[_i7], 2),
|
|
760
|
-
k = _Object$entries6$_i[0],
|
|
761
|
-
v = _Object$entries6$_i[1];
|
|
762
|
-
result[k] = _processValue(v);
|
|
763
|
-
}
|
|
764
|
-
return result;
|
|
765
|
-
}
|
|
766
|
-
return value;
|
|
767
|
-
};
|
|
768
|
-
processedObj = {};
|
|
769
|
-
for (_i8 = 0, _Object$entries7 = Object.entries(obj); _i8 < _Object$entries7.length; _i8++) {
|
|
770
|
-
_Object$entries7$_i = _slicedToArray(_Object$entries7[_i8], 2), k = _Object$entries7$_i[0], v = _Object$entries7$_i[1];
|
|
771
|
-
processedObj[k] = _processValue(v);
|
|
1202
|
+
obj = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
|
|
1203
|
+
// Step 1: Process and normalize input values
|
|
1204
|
+
processedObj = processInputValues(obj); // Step 2: Handle empty object case
|
|
1205
|
+
emptyResult = handleEmptyObject(processedObj);
|
|
1206
|
+
if (!emptyResult) {
|
|
1207
|
+
_context8.next = 5;
|
|
1208
|
+
break;
|
|
772
1209
|
}
|
|
773
|
-
|
|
774
|
-
|
|
1210
|
+
return _context8.abrupt("return", emptyResult);
|
|
1211
|
+
case 5:
|
|
1212
|
+
// Step 3: Handle single field with empty binary
|
|
1213
|
+
emptyBinaryResult = handleSingleEmptyBinaryField(processedObj);
|
|
1214
|
+
if (!emptyBinaryResult) {
|
|
1215
|
+
_context8.next = 8;
|
|
775
1216
|
break;
|
|
776
1217
|
}
|
|
777
|
-
return
|
|
778
|
-
headers: {},
|
|
779
|
-
body: undefined
|
|
780
|
-
});
|
|
1218
|
+
return _context8.abrupt("return", emptyBinaryResult);
|
|
781
1219
|
case 8:
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
1220
|
+
_context8.next = 10;
|
|
1221
|
+
return handleSingleBinaryField(processedObj);
|
|
1222
|
+
case 10:
|
|
1223
|
+
singleBinaryResult = _context8.sent;
|
|
1224
|
+
if (!singleBinaryResult) {
|
|
1225
|
+
_context8.next = 13;
|
|
785
1226
|
break;
|
|
786
1227
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
1228
|
+
return _context8.abrupt("return", singleBinaryResult);
|
|
1229
|
+
case 13:
|
|
1230
|
+
_context8.next = 15;
|
|
1231
|
+
return handleSinglePrimitiveField(processedObj);
|
|
1232
|
+
case 15:
|
|
1233
|
+
primitiveResult = _context8.sent;
|
|
1234
|
+
if (!primitiveResult) {
|
|
1235
|
+
_context8.next = 18;
|
|
791
1236
|
break;
|
|
792
1237
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
hasBodyBinary = obj.body && isBytes(obj.body);
|
|
802
|
-
otherFields = Object.keys(obj).filter(function (k) {
|
|
803
|
-
return k !== "body";
|
|
804
|
-
});
|
|
805
|
-
if (!(hasBodyBinary && otherFields.length === 0)) {
|
|
806
|
-
_context6.next = 29;
|
|
1238
|
+
return _context8.abrupt("return", primitiveResult);
|
|
1239
|
+
case 18:
|
|
1240
|
+
_context8.next = 20;
|
|
1241
|
+
return handleSingleNonEmptyBinaryField(processedObj);
|
|
1242
|
+
case 20:
|
|
1243
|
+
nonEmptyBinaryResult = _context8.sent;
|
|
1244
|
+
if (!nonEmptyBinaryResult) {
|
|
1245
|
+
_context8.next = 23;
|
|
807
1246
|
break;
|
|
808
1247
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
return sha256(bodyArrayBuffer);
|
|
1248
|
+
return _context8.abrupt("return", nonEmptyBinaryResult);
|
|
1249
|
+
case 23:
|
|
1250
|
+
_context8.next = 25;
|
|
1251
|
+
return handleSingleNonAsciiStringField(processedObj);
|
|
814
1252
|
case 25:
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
return _context6.abrupt("return", {
|
|
819
|
-
headers: _headers2,
|
|
820
|
-
body: obj.body
|
|
821
|
-
});
|
|
822
|
-
case 29:
|
|
823
|
-
if (!(objKeys.length === 1)) {
|
|
824
|
-
_context6.next = 71;
|
|
825
|
-
break;
|
|
826
|
-
}
|
|
827
|
-
_fieldName = objKeys[0];
|
|
828
|
-
_fieldValue = obj[_fieldName];
|
|
829
|
-
if (!(isBytes(_fieldValue) && _fieldValue.length > 0)) {
|
|
830
|
-
_context6.next = 45;
|
|
1253
|
+
nonAsciiResult = _context8.sent;
|
|
1254
|
+
if (!nonAsciiResult) {
|
|
1255
|
+
_context8.next = 28;
|
|
831
1256
|
break;
|
|
832
1257
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
case 38:
|
|
839
|
-
_contentDigest = _context6.sent;
|
|
840
|
-
_base = _base64url["default"].toBase64(_base64url["default"].encode(_contentDigest));
|
|
841
|
-
_headers3["content-digest"] = "sha-256=:".concat(_base, ":");
|
|
842
|
-
if (_fieldName !== "body") {
|
|
843
|
-
_headers3["inline-body-key"] = _fieldName;
|
|
844
|
-
}
|
|
845
|
-
return _context6.abrupt("return", {
|
|
846
|
-
headers: _headers3,
|
|
847
|
-
body: _fieldValue
|
|
848
|
-
});
|
|
849
|
-
case 45:
|
|
850
|
-
if (!((_fieldName === "data" || _fieldName === "body") && (typeof _fieldValue === "string" || typeof _fieldValue === "boolean" || typeof _fieldValue === "number" || _fieldValue === null || _fieldValue === undefined || _typeof(_fieldValue) === "symbol"))) {
|
|
851
|
-
_context6.next = 60;
|
|
852
|
-
break;
|
|
853
|
-
}
|
|
854
|
-
_headers4 = {};
|
|
855
|
-
if (typeof _fieldValue === "string") {
|
|
856
|
-
bodyContent = _fieldValue;
|
|
857
|
-
} else if (typeof _fieldValue === "boolean") {
|
|
858
|
-
bodyContent = "\"".concat(_fieldValue, "\"");
|
|
859
|
-
} else if (typeof _fieldValue === "number") {
|
|
860
|
-
bodyContent = String(_fieldValue);
|
|
861
|
-
} else if (_fieldValue === null) {
|
|
862
|
-
bodyContent = '"null"';
|
|
863
|
-
} else if (_fieldValue === undefined) {
|
|
864
|
-
bodyContent = '"undefined"';
|
|
865
|
-
} else if (_typeof(_fieldValue) === "symbol") {
|
|
866
|
-
bodyContent = "\"".concat(_fieldValue.description || "Symbol.for()", "\"");
|
|
867
|
-
}
|
|
868
|
-
encoder = new TextEncoder();
|
|
869
|
-
encoded = encoder.encode(bodyContent);
|
|
870
|
-
_context6.next = 52;
|
|
871
|
-
return sha256(encoded.buffer);
|
|
872
|
-
case 52:
|
|
873
|
-
_contentDigest2 = _context6.sent;
|
|
874
|
-
_base2 = _base64url["default"].toBase64(_base64url["default"].encode(_contentDigest2));
|
|
875
|
-
_headers4["content-digest"] = "sha-256=:".concat(_base2, ":");
|
|
876
|
-
if (typeof _fieldValue === "boolean" || _fieldValue === null || _fieldValue === undefined || _typeof(_fieldValue) === "symbol") {
|
|
877
|
-
_headers4["ao-types"] = "".concat(_fieldName.toLowerCase(), "=\"atom\"");
|
|
878
|
-
} else if (typeof _fieldValue === "number") {
|
|
879
|
-
_headers4["ao-types"] = "".concat(_fieldName.toLowerCase(), "=\"").concat(Number.isInteger(_fieldValue) ? "integer" : "float", "\"");
|
|
880
|
-
}
|
|
881
|
-
if (_fieldName !== "body") {
|
|
882
|
-
_headers4["inline-body-key"] = _fieldName;
|
|
883
|
-
}
|
|
884
|
-
return _context6.abrupt("return", {
|
|
885
|
-
headers: _headers4,
|
|
886
|
-
body: bodyContent
|
|
887
|
-
});
|
|
888
|
-
case 60:
|
|
889
|
-
if (!(typeof _fieldValue === "string" && hasNonAscii(_fieldValue))) {
|
|
890
|
-
_context6.next = 71;
|
|
891
|
-
break;
|
|
892
|
-
}
|
|
893
|
-
_headers5 = {};
|
|
894
|
-
_encoder = new TextEncoder();
|
|
895
|
-
_encoded = _encoder.encode(_fieldValue);
|
|
896
|
-
_context6.next = 66;
|
|
897
|
-
return sha256(_encoded.buffer);
|
|
898
|
-
case 66:
|
|
899
|
-
_contentDigest3 = _context6.sent;
|
|
900
|
-
_base3 = _base64url["default"].toBase64(_base64url["default"].encode(_contentDigest3));
|
|
901
|
-
_headers5["content-digest"] = "sha-256=:".concat(_base3, ":");
|
|
902
|
-
if (_fieldName !== "body") {
|
|
903
|
-
_headers5["inline-body-key"] = _fieldName;
|
|
904
|
-
}
|
|
905
|
-
return _context6.abrupt("return", {
|
|
906
|
-
headers: _headers5,
|
|
907
|
-
body: _fieldValue
|
|
908
|
-
});
|
|
909
|
-
case 71:
|
|
910
|
-
bodyKeys = collectBodyKeys(obj);
|
|
1258
|
+
return _context8.abrupt("return", nonAsciiResult);
|
|
1259
|
+
case 28:
|
|
1260
|
+
// Step 7: Collect all keys that need to go in body
|
|
1261
|
+
bodyKeys = collectBodyKeysStep(processedObj);
|
|
1262
|
+
objKeys = Object.keys(obj);
|
|
911
1263
|
headers = {};
|
|
912
|
-
headerTypes = [];
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
needsBody = bodyKeys.includes(key) || bodyKeys.some(function (k) {
|
|
920
|
-
return k.startsWith("".concat(key, "/"));
|
|
921
|
-
});
|
|
922
|
-
if (needsBody) {
|
|
923
|
-
_context3.next = 43;
|
|
924
|
-
break;
|
|
925
|
-
}
|
|
926
|
-
if (!(value === null)) {
|
|
927
|
-
_context3.next = 8;
|
|
928
|
-
break;
|
|
929
|
-
}
|
|
930
|
-
headers[key] = '"null"';
|
|
931
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
932
|
-
_context3.next = 41;
|
|
933
|
-
break;
|
|
934
|
-
case 8:
|
|
935
|
-
if (!(value === undefined)) {
|
|
936
|
-
_context3.next = 13;
|
|
937
|
-
break;
|
|
938
|
-
}
|
|
939
|
-
headers[key] = '"undefined"';
|
|
940
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
941
|
-
_context3.next = 41;
|
|
942
|
-
break;
|
|
943
|
-
case 13:
|
|
944
|
-
if (!(typeof value === "boolean")) {
|
|
945
|
-
_context3.next = 18;
|
|
946
|
-
break;
|
|
947
|
-
}
|
|
948
|
-
headers[key] = "\"".concat(value, "\"");
|
|
949
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
950
|
-
_context3.next = 41;
|
|
951
|
-
break;
|
|
952
|
-
case 18:
|
|
953
|
-
if (!(_typeof(value) === "symbol")) {
|
|
954
|
-
_context3.next = 23;
|
|
955
|
-
break;
|
|
956
|
-
}
|
|
957
|
-
headers[key] = "\"".concat(value.description || "Symbol.for()", "\"");
|
|
958
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
959
|
-
_context3.next = 41;
|
|
960
|
-
break;
|
|
961
|
-
case 23:
|
|
962
|
-
if (!(typeof value === "number")) {
|
|
963
|
-
_context3.next = 28;
|
|
964
|
-
break;
|
|
965
|
-
}
|
|
966
|
-
headers[key] = String(value);
|
|
967
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"").concat(Number.isInteger(value) ? "integer" : "float", "\""));
|
|
968
|
-
_context3.next = 41;
|
|
969
|
-
break;
|
|
970
|
-
case 28:
|
|
971
|
-
if (!(typeof value === "string")) {
|
|
972
|
-
_context3.next = 40;
|
|
973
|
-
break;
|
|
974
|
-
}
|
|
975
|
-
if (!(value.length === 0)) {
|
|
976
|
-
_context3.next = 33;
|
|
977
|
-
break;
|
|
978
|
-
}
|
|
979
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-binary\""));
|
|
980
|
-
_context3.next = 38;
|
|
981
|
-
break;
|
|
982
|
-
case 33:
|
|
983
|
-
if (!hasNonAscii(value)) {
|
|
984
|
-
_context3.next = 37;
|
|
985
|
-
break;
|
|
986
|
-
}
|
|
987
|
-
return _context3.abrupt("return", 1);
|
|
988
|
-
case 37:
|
|
989
|
-
headers[key] = value;
|
|
990
|
-
case 38:
|
|
991
|
-
_context3.next = 41;
|
|
992
|
-
break;
|
|
993
|
-
case 40:
|
|
994
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
995
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-list\""));
|
|
996
|
-
} else if (Array.isArray(value) && !value.some(function (item) {
|
|
997
|
-
return isPojo(item);
|
|
998
|
-
})) {
|
|
999
|
-
hasNonAsciiItems = value.some(function (item) {
|
|
1000
|
-
return typeof item === "string" && hasNonAscii(item);
|
|
1001
|
-
});
|
|
1002
|
-
if (!hasNonAsciiItems) {
|
|
1003
|
-
encodedItems = value.map(function (item) {
|
|
1004
|
-
return encodeArrayItem(item);
|
|
1005
|
-
}).join(", ");
|
|
1006
|
-
headers[key] = encodedItems;
|
|
1007
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"list\""));
|
|
1008
|
-
}
|
|
1009
|
-
} else if (isBytes(value) && (value.length === 0 || value.byteLength === 0)) {
|
|
1010
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-binary\""));
|
|
1011
|
-
} else if (isPojo(value) && Object.keys(value).length === 0) {
|
|
1012
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-message\""));
|
|
1013
|
-
}
|
|
1014
|
-
case 41:
|
|
1015
|
-
_context3.next = 44;
|
|
1016
|
-
break;
|
|
1017
|
-
case 43:
|
|
1018
|
-
if (isBytes(value) && (value.length === 0 || value.byteLength === 0)) {
|
|
1019
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-binary\""));
|
|
1020
|
-
} else if (typeof value === "string" && value.length === 0) {
|
|
1021
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-binary\""));
|
|
1022
|
-
} else if (Array.isArray(value) && value.length === 0) {
|
|
1023
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-list\""));
|
|
1024
|
-
} else if (isPojo(value) && Object.keys(value).length === 0) {
|
|
1025
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"empty-message\""));
|
|
1026
|
-
} else if (typeof value === "boolean" || value === null || value === undefined || _typeof(value) === "symbol") {
|
|
1027
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"atom\""));
|
|
1028
|
-
} else if (typeof value === "number") {
|
|
1029
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"").concat(Number.isInteger(value) ? "integer" : "float", "\""));
|
|
1030
|
-
}
|
|
1031
|
-
case 44:
|
|
1032
|
-
case "end":
|
|
1033
|
-
return _context3.stop();
|
|
1034
|
-
}
|
|
1035
|
-
}, _loop3);
|
|
1036
|
-
});
|
|
1037
|
-
_i9 = 0, _Object$entries8 = Object.entries(obj);
|
|
1038
|
-
case 76:
|
|
1039
|
-
if (!(_i9 < _Object$entries8.length)) {
|
|
1040
|
-
_context6.next = 83;
|
|
1041
|
-
break;
|
|
1042
|
-
}
|
|
1043
|
-
return _context6.delegateYield(_loop3(), "t0", 78);
|
|
1044
|
-
case 78:
|
|
1045
|
-
if (!_context6.t0) {
|
|
1046
|
-
_context6.next = 80;
|
|
1047
|
-
break;
|
|
1048
|
-
}
|
|
1049
|
-
return _context6.abrupt("continue", 80);
|
|
1050
|
-
case 80:
|
|
1051
|
-
_i9++;
|
|
1052
|
-
_context6.next = 76;
|
|
1053
|
-
break;
|
|
1054
|
-
case 83:
|
|
1055
|
-
_loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
|
|
1056
|
-
var _Object$entries9$_i, key, value;
|
|
1057
|
-
return _regeneratorRuntime().wrap(function _loop4$(_context4) {
|
|
1058
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
1059
|
-
case 0:
|
|
1060
|
-
_Object$entries9$_i = _slicedToArray(_Object$entries9[_i10], 2), key = _Object$entries9$_i[0], value = _Object$entries9$_i[1];
|
|
1061
|
-
if (Array.isArray(value)) {
|
|
1062
|
-
if (bodyKeys.includes(key) || bodyKeys.some(function (k) {
|
|
1063
|
-
return k.startsWith("".concat(key, "/"));
|
|
1064
|
-
})) {
|
|
1065
|
-
if (!headerTypes.some(function (t) {
|
|
1066
|
-
return t.startsWith("".concat(key.toLowerCase(), "="));
|
|
1067
|
-
})) {
|
|
1068
|
-
headerTypes.push("".concat(key.toLowerCase(), "=\"list\""));
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
case 2:
|
|
1073
|
-
case "end":
|
|
1074
|
-
return _context4.stop();
|
|
1075
|
-
}
|
|
1076
|
-
}, _loop4);
|
|
1077
|
-
});
|
|
1078
|
-
_i10 = 0, _Object$entries9 = Object.entries(obj);
|
|
1079
|
-
case 85:
|
|
1080
|
-
if (!(_i10 < _Object$entries9.length)) {
|
|
1081
|
-
_context6.next = 90;
|
|
1082
|
-
break;
|
|
1083
|
-
}
|
|
1084
|
-
return _context6.delegateYield(_loop4(), "t1", 87);
|
|
1085
|
-
case 87:
|
|
1086
|
-
_i10++;
|
|
1087
|
-
_context6.next = 85;
|
|
1088
|
-
break;
|
|
1089
|
-
case 90:
|
|
1090
|
-
if (!(bodyKeys.length === 0)) {
|
|
1091
|
-
_context6.next = 94;
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
console.log("No bodyKeys, returning headers only");
|
|
1095
|
-
if (headerTypes.length > 0) {
|
|
1096
|
-
headers["ao-types"] = headerTypes.sort().join(", ");
|
|
1097
|
-
}
|
|
1098
|
-
return _context6.abrupt("return", {
|
|
1099
|
-
headers: headers,
|
|
1100
|
-
body: undefined
|
|
1101
|
-
});
|
|
1102
|
-
case 94:
|
|
1103
|
-
allBodyKeysAreEmptyBinaries = bodyKeys.every(function (key) {
|
|
1104
|
-
var pathParts = key.split("/");
|
|
1105
|
-
var value = obj;
|
|
1106
|
-
var _iterator3 = _createForOfIteratorHelper(pathParts),
|
|
1107
|
-
_step3;
|
|
1108
|
-
try {
|
|
1109
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1110
|
-
var part = _step3.value;
|
|
1111
|
-
if (/^\d+$/.test(part)) {
|
|
1112
|
-
var index = parseInt(part) - 1;
|
|
1113
|
-
console.log("[Body part] Getting array element at index ".concat(index, " from part ").concat(part));
|
|
1114
|
-
value = value[index];
|
|
1115
|
-
} else {
|
|
1116
|
-
value = value[part];
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
} catch (err) {
|
|
1120
|
-
_iterator3.e(err);
|
|
1121
|
-
} finally {
|
|
1122
|
-
_iterator3.f();
|
|
1123
|
-
}
|
|
1124
|
-
return isBytes(value) && (value.length === 0 || value.byteLength === 0);
|
|
1125
|
-
});
|
|
1126
|
-
if (!allBodyKeysAreEmptyBinaries) {
|
|
1127
|
-
_context6.next = 98;
|
|
1128
|
-
break;
|
|
1129
|
-
}
|
|
1130
|
-
if (headerTypes.length > 0) {
|
|
1131
|
-
headers["ao-types"] = headerTypes.sort().join(", ");
|
|
1132
|
-
}
|
|
1133
|
-
return _context6.abrupt("return", {
|
|
1134
|
-
headers: headers,
|
|
1135
|
-
body: undefined
|
|
1136
|
-
});
|
|
1137
|
-
case 98:
|
|
1138
|
-
if (!(bodyKeys.length === 1)) {
|
|
1139
|
-
_context6.next = 116;
|
|
1264
|
+
headerTypes = []; // Step 8: Process fields that can go in headers
|
|
1265
|
+
processHeaderFields(obj, bodyKeys, headers, headerTypes);
|
|
1266
|
+
|
|
1267
|
+
// Step 9: Handle case where all body keys are empty binaries
|
|
1268
|
+
emptyBinaryBodyResult = handleAllEmptyBinaryBodyKeys(obj, bodyKeys, headers, headerTypes);
|
|
1269
|
+
if (!emptyBinaryBodyResult) {
|
|
1270
|
+
_context8.next = 36;
|
|
1140
1271
|
break;
|
|
1141
1272
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
value = value[parseInt(part) - 1];
|
|
1151
|
-
} else {
|
|
1152
|
-
value = value[part];
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
} catch (err) {
|
|
1156
|
-
_iterator4.e(err);
|
|
1157
|
-
} finally {
|
|
1158
|
-
_iterator4.f();
|
|
1159
|
-
}
|
|
1160
|
-
otherFieldsAreEmpty = Object.entries(obj).every(function (_ref5) {
|
|
1161
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
1162
|
-
key = _ref6[0],
|
|
1163
|
-
val = _ref6[1];
|
|
1164
|
-
if (key === singleKey) return true;
|
|
1165
|
-
return Array.isArray(val) && val.length === 0 || isPojo(val) && Object.keys(val).length === 0 || isBytes(val) && (val.length === 0 || val.byteLength === 0) || typeof val === "string" && val.length === 0;
|
|
1166
|
-
});
|
|
1167
|
-
if (!(otherFieldsAreEmpty && isBytes(value) && value.length > 0)) {
|
|
1168
|
-
_context6.next = 116;
|
|
1273
|
+
return _context8.abrupt("return", emptyBinaryBodyResult);
|
|
1274
|
+
case 36:
|
|
1275
|
+
_context8.next = 38;
|
|
1276
|
+
return handleSingleBodyKeyOptimization(obj, bodyKeys, headers, headerTypes);
|
|
1277
|
+
case 38:
|
|
1278
|
+
singleBodyKeyResult = _context8.sent;
|
|
1279
|
+
if (!singleBodyKeyResult) {
|
|
1280
|
+
_context8.next = 41;
|
|
1169
1281
|
break;
|
|
1170
1282
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
_contentDigest4 = _context6.sent;
|
|
1177
|
-
_base4 = _base64url["default"].toBase64(_base64url["default"].encode(_contentDigest4));
|
|
1178
|
-
headers["content-digest"] = "sha-256=:".concat(_base4, ":");
|
|
1179
|
-
if (singleKey !== "body") {
|
|
1180
|
-
headers["inline-body-key"] = singleKey;
|
|
1181
|
-
}
|
|
1182
|
-
if (headerTypes.length > 0) {
|
|
1183
|
-
headers["ao-types"] = headerTypes.sort().join(", ");
|
|
1184
|
-
}
|
|
1185
|
-
return _context6.abrupt("return", {
|
|
1186
|
-
headers: headers,
|
|
1187
|
-
body: value
|
|
1188
|
-
});
|
|
1189
|
-
case 116:
|
|
1190
|
-
// Sort body keys: main array comes first, then element parts by index
|
|
1191
|
-
sortedBodyKeys = bodyKeys.sort(function (a, b) {
|
|
1192
|
-
var aIsArrayElement = /\/\d+$/.test(a);
|
|
1193
|
-
var bIsArrayElement = /\/\d+$/.test(b);
|
|
1194
|
-
var aBase = a.split("/")[0];
|
|
1195
|
-
var bBase = b.split("/")[0];
|
|
1196
|
-
|
|
1197
|
-
// If both are for the same array
|
|
1198
|
-
if (aBase === bBase) {
|
|
1199
|
-
// Main array comes before element parts
|
|
1200
|
-
if (!aIsArrayElement && bIsArrayElement) {
|
|
1201
|
-
return -1; // main array comes first
|
|
1202
|
-
}
|
|
1203
|
-
if (aIsArrayElement && !bIsArrayElement) {
|
|
1204
|
-
return 1; // element parts come after
|
|
1205
|
-
}
|
|
1206
|
-
// Both are elements - sort by index
|
|
1207
|
-
if (aIsArrayElement && bIsArrayElement) {
|
|
1208
|
-
var aIndex = parseInt(a.split("/")[1]);
|
|
1209
|
-
var bIndex = parseInt(b.split("/")[1]);
|
|
1210
|
-
return aIndex - bIndex;
|
|
1211
|
-
}
|
|
1212
|
-
return a.localeCompare(b);
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
// Different arrays, sort by base name
|
|
1216
|
-
return a.localeCompare(b);
|
|
1217
|
-
}); // Check if we have the special case where data contains body with bytes and body contains data with bytes
|
|
1218
|
-
hasSpecialDataBody = sortedBodyKeys.includes("data") && sortedBodyKeys.includes("body") && obj.data && obj.data.body && isBytes(obj.data.body) && obj.body && obj.body.data && isBytes(obj.body.data);
|
|
1283
|
+
return _context8.abrupt("return", singleBodyKeyResult);
|
|
1284
|
+
case 41:
|
|
1285
|
+
// Step 11: Sort body keys
|
|
1286
|
+
sortedBodyKeys = sortBodyKeys(bodyKeys); // Step 12: Check for special data/body case
|
|
1287
|
+
hasSpecialDataBody = checkSpecialDataBodyCase(obj, sortedBodyKeys);
|
|
1219
1288
|
headers["body-keys"] = sortedBodyKeys.map(function (k) {
|
|
1220
1289
|
return "\"".concat(k, "\"");
|
|
1221
1290
|
}).join(", ");
|
|
@@ -1227,481 +1296,54 @@ function _encode() {
|
|
|
1227
1296
|
if (headerTypes.length > 0) {
|
|
1228
1297
|
headers["ao-types"] = headerTypes.sort().join(", ");
|
|
1229
1298
|
}
|
|
1230
|
-
bodyParts = [];
|
|
1231
|
-
_iterator5 = _createForOfIteratorHelper(sortedBodyKeys);
|
|
1232
|
-
_context6.prev = 123;
|
|
1233
|
-
_loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
|
|
1234
|
-
var bodyKey, lines, pathParts, value, parent, _i11, _part, _buffer, headerText, hasOnlyEmptyElements, hasOnlyNonEmptyObjects, hasOnlyEmptyObjects, hasObjects, hasArrays, nonObjectItems, _fieldLines, _partTypes, _isInline, orderedLines, _orderedLines, isLastBodyPart, hasOnlyTypes, indicesWithOwnParts, hasNestedObjectParts, fieldLines, partTypes, hasEmptyStrings, hasEmptyObjects, hasObjectsWithOnlyEmptyValues, isMixedArray, _isInline2, _orderedLines2, _iterator6, _step6, line, _orderedLines3, _iterator7, _step7, _line, isInline, content;
|
|
1235
|
-
return _regeneratorRuntime().wrap(function _loop5$(_context5) {
|
|
1236
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
1237
|
-
case 0:
|
|
1238
|
-
bodyKey = _step5.value;
|
|
1239
|
-
console.log("\n[Body part] Processing bodyKey: ".concat(bodyKey));
|
|
1240
|
-
lines = [];
|
|
1241
|
-
pathParts = bodyKey.split("/");
|
|
1242
|
-
value = obj;
|
|
1243
|
-
parent = null;
|
|
1244
|
-
for (_i11 = 0; _i11 < pathParts.length; _i11++) {
|
|
1245
|
-
parent = value;
|
|
1246
|
-
_part = pathParts[_i11];
|
|
1247
|
-
if (/^\d+$/.test(_part)) {
|
|
1248
|
-
value = value[parseInt(_part) - 1];
|
|
1249
|
-
} else {
|
|
1250
|
-
value = value[_part];
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
console.log("[Body part] Value at ".concat(bodyKey, ":"), JSON.stringify(value));
|
|
1254
|
-
|
|
1255
|
-
// Special handling for empty strings in arrays
|
|
1256
|
-
if (!(typeof value === "string" && value === "" && pathParts.length > 1)) {
|
|
1257
|
-
_context5.next = 15;
|
|
1258
|
-
break;
|
|
1259
|
-
}
|
|
1260
|
-
console.log("[Body part] Creating part for empty string at ".concat(bodyKey));
|
|
1261
|
-
lines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
1262
|
-
lines.push("");
|
|
1263
|
-
lines.push("");
|
|
1264
|
-
bodyParts.push(new Blob([lines.join("\r\n")]));
|
|
1265
|
-
return _context5.abrupt("return", 0);
|
|
1266
|
-
case 15:
|
|
1267
|
-
if (!isBytes(value)) {
|
|
1268
|
-
_context5.next = 22;
|
|
1269
|
-
break;
|
|
1270
|
-
}
|
|
1271
|
-
console.log("[Body part] Creating part for binary at ".concat(bodyKey));
|
|
1272
|
-
lines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
1273
|
-
_buffer = toBuffer(value);
|
|
1274
|
-
headerText = lines.join("\r\n") + "\r\n\r\n";
|
|
1275
|
-
bodyParts.push(new Blob([headerText, _buffer]));
|
|
1276
|
-
return _context5.abrupt("return", 0);
|
|
1277
|
-
case 22:
|
|
1278
|
-
if (!Array.isArray(value)) {
|
|
1279
|
-
_context5.next = 52;
|
|
1280
|
-
break;
|
|
1281
|
-
}
|
|
1282
|
-
hasOnlyEmptyElements = value.length > 0 && value.every(function (item) {
|
|
1283
|
-
return Array.isArray(item) && item.length === 0 || isPojo(item) && Object.keys(item).length === 0 || typeof item === "string" && item === "";
|
|
1284
|
-
});
|
|
1285
|
-
hasOnlyNonEmptyObjects = value.length > 0 && value.every(function (item) {
|
|
1286
|
-
return isPojo(item) && Object.keys(item).length > 0;
|
|
1287
|
-
});
|
|
1288
|
-
hasOnlyEmptyObjects = value.length > 0 && value.every(function (item) {
|
|
1289
|
-
return isPojo(item) && Object.keys(item).length === 0;
|
|
1290
|
-
});
|
|
1291
|
-
hasObjects = value.some(function (item) {
|
|
1292
|
-
return isPojo(item);
|
|
1293
|
-
});
|
|
1294
|
-
hasArrays = value.some(function (item) {
|
|
1295
|
-
return Array.isArray(item);
|
|
1296
|
-
});
|
|
1297
|
-
nonObjectItems = value.map(function (item, index) {
|
|
1298
|
-
return {
|
|
1299
|
-
item: item,
|
|
1300
|
-
index: index + 1
|
|
1301
|
-
};
|
|
1302
|
-
}).filter(function (_ref7) {
|
|
1303
|
-
var item = _ref7.item;
|
|
1304
|
-
return !isPojo(item);
|
|
1305
|
-
});
|
|
1306
|
-
if (!hasOnlyNonEmptyObjects) {
|
|
1307
|
-
_context5.next = 31;
|
|
1308
|
-
break;
|
|
1309
|
-
}
|
|
1310
|
-
return _context5.abrupt("return", 0);
|
|
1311
|
-
case 31:
|
|
1312
|
-
if (!hasOnlyEmptyElements) {
|
|
1313
|
-
_context5.next = 38;
|
|
1314
|
-
break;
|
|
1315
|
-
}
|
|
1316
|
-
_fieldLines = [];
|
|
1317
|
-
_partTypes = []; // Process items for type information
|
|
1318
|
-
value.forEach(function (item, idx) {
|
|
1319
|
-
var index = idx + 1;
|
|
1320
|
-
if (Array.isArray(item) && item.length === 0) {
|
|
1321
|
-
_partTypes.push("".concat(index, "=\"empty-list\""));
|
|
1322
|
-
} else if (isPojo(item) && Object.keys(item).length === 0) {
|
|
1323
|
-
_partTypes.push("".concat(index, "=\"empty-message\""));
|
|
1324
|
-
} else if (typeof item === "string" && item === "") {
|
|
1325
|
-
_partTypes.push("".concat(index, "=\"empty-binary\""));
|
|
1326
|
-
}
|
|
1327
|
-
});
|
|
1328
|
-
_isInline = bodyKey === "body" && headers["inline-body-key"] === "body";
|
|
1329
|
-
if (_isInline) {
|
|
1330
|
-
orderedLines = [];
|
|
1331
|
-
if (_partTypes.length > 0) {
|
|
1332
|
-
orderedLines.push("ao-types: ".concat(_partTypes.sort(function (a, b) {
|
|
1333
|
-
var aNum = parseInt(a.split("=")[0]);
|
|
1334
|
-
var bNum = parseInt(b.split("=")[0]);
|
|
1335
|
-
return aNum - bNum;
|
|
1336
|
-
}).join(", ")));
|
|
1337
|
-
}
|
|
1338
|
-
orderedLines.push("content-disposition: inline");
|
|
1339
|
-
orderedLines.push("");
|
|
1340
|
-
bodyParts.push(new Blob([orderedLines.join("\r\n")]));
|
|
1341
|
-
} else {
|
|
1342
|
-
_orderedLines = [];
|
|
1343
|
-
if (_partTypes.length > 0) {
|
|
1344
|
-
_orderedLines.push("ao-types: ".concat(_partTypes.sort(function (a, b) {
|
|
1345
|
-
var aNum = parseInt(a.split("=")[0]);
|
|
1346
|
-
var bNum = parseInt(b.split("=")[0]);
|
|
1347
|
-
return aNum - bNum;
|
|
1348
|
-
}).join(", ")));
|
|
1349
|
-
}
|
|
1350
|
-
_orderedLines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
1351
1299
|
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
if (key.startsWith(bodyKey + "/")) {
|
|
1369
|
-
var subPath = key.substring(bodyKey.length + 1);
|
|
1370
|
-
var match = subPath.match(/^(\d+)/);
|
|
1371
|
-
if (match) {
|
|
1372
|
-
indicesWithOwnParts.add(parseInt(match[1]));
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
});
|
|
1300
|
+
// Step 13: Build body parts for each body key
|
|
1301
|
+
bodyParts = buildBodyParts(obj, sortedBodyKeys, headers, hasSpecialDataBody); // Step 14: Generate multipart boundary
|
|
1302
|
+
_context8.next = 49;
|
|
1303
|
+
return generateBoundary(bodyParts);
|
|
1304
|
+
case 49:
|
|
1305
|
+
boundary = _context8.sent;
|
|
1306
|
+
// Step 15: Assemble final multipart body
|
|
1307
|
+
body = assembleMultipartBody(bodyParts, boundary); // Step 16: Calculate content digest
|
|
1308
|
+
_context8.next = 53;
|
|
1309
|
+
return calculateContentDigest(body);
|
|
1310
|
+
case 53:
|
|
1311
|
+
_yield$calculateConte = _context8.sent;
|
|
1312
|
+
contentDigest = _yield$calculateConte.digest;
|
|
1313
|
+
byteLength = _yield$calculateConte.byteLength;
|
|
1314
|
+
// Step 17: Set final headers (content-type, content-length)
|
|
1315
|
+
setFinalHeaders(headers, boundary, contentDigest, byteLength);
|
|
1376
1316
|
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
return key.startsWith(bodyKey + "/") && key.split("/").length > pathParts.length + 1;
|
|
1380
|
-
});
|
|
1381
|
-
fieldLines = [];
|
|
1382
|
-
partTypes = []; // For arrays that contain sub-arrays with objects, we need to add type info for the sub-arrays
|
|
1383
|
-
if (hasNestedObjectParts) {
|
|
1384
|
-
value.forEach(function (item, idx) {
|
|
1385
|
-
var index = idx + 1;
|
|
1386
|
-
if (Array.isArray(item)) {
|
|
1387
|
-
partTypes.push("".concat(index, "=\"list\""));
|
|
1388
|
-
}
|
|
1389
|
-
});
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
// Check if this array has mixed content with empty strings/objects
|
|
1393
|
-
hasEmptyStrings = value.some(function (item) {
|
|
1394
|
-
return typeof item === "string" && item === "";
|
|
1395
|
-
});
|
|
1396
|
-
hasEmptyObjects = value.some(function (item) {
|
|
1397
|
-
return isPojo(item) && Object.keys(item).length === 0;
|
|
1398
|
-
}); // Check if we have objects with only empty values (like {empty: ""})
|
|
1399
|
-
hasObjectsWithOnlyEmptyValues = value.some(function (item) {
|
|
1400
|
-
if (!isPojo(item) || Object.keys(item).length === 0) return false;
|
|
1401
|
-
return Object.values(item).every(function (v) {
|
|
1402
|
-
return typeof v === "string" && v === "" || Array.isArray(v) && v.length === 0 || isPojo(v) && Object.keys(v).length === 0;
|
|
1403
|
-
});
|
|
1404
|
-
});
|
|
1405
|
-
isMixedArray = hasObjects && (hasEmptyStrings || hasEmptyObjects) && !hasObjectsWithOnlyEmptyValues; // Process ALL items for type information
|
|
1406
|
-
value.forEach(function (item, idx) {
|
|
1407
|
-
var index = idx + 1;
|
|
1408
|
-
|
|
1409
|
-
// Skip type info for elements that have their own parts
|
|
1410
|
-
if (indicesWithOwnParts.has(index)) {
|
|
1411
|
-
return;
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
// If we have nested object parts and this is an array with objects, skip processing it inline
|
|
1415
|
-
if (hasNestedObjectParts && Array.isArray(item) && item.some(function (subItem) {
|
|
1416
|
-
return isPojo(subItem);
|
|
1417
|
-
})) {
|
|
1418
|
-
// Type info already added above
|
|
1419
|
-
return;
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
// For all arrays (not just mixed ones), we need to process all items
|
|
1423
|
-
if (typeof item === "string" && item === "") {
|
|
1424
|
-
// Empty strings get type annotation but no field line
|
|
1425
|
-
partTypes.push("".concat(index, "=\"empty-binary\""));
|
|
1426
|
-
} else if (isPojo(item) && Object.keys(item).length === 0) {
|
|
1427
|
-
// Empty objects don't get field lines but do get type annotations
|
|
1428
|
-
partTypes.push("".concat(index, "=\"empty-message\""));
|
|
1429
|
-
} else if (isPojo(item)) {
|
|
1430
|
-
// Non-empty objects might have parts
|
|
1431
|
-
} else if (Array.isArray(item)) {
|
|
1432
|
-
if (item.length === 0) {
|
|
1433
|
-
// Empty arrays don't get field lines but do get type annotations
|
|
1434
|
-
partTypes.push("".concat(index, "=\"empty-list\""));
|
|
1435
|
-
} else {
|
|
1436
|
-
partTypes.push("".concat(index, "=\"list\""));
|
|
1437
|
-
// Encode array
|
|
1438
|
-
var encodedItems = item.map(function (subItem) {
|
|
1439
|
-
if (typeof subItem === "number") {
|
|
1440
|
-
if (Number.isInteger(subItem)) {
|
|
1441
|
-
return "\"(ao-type-integer) ".concat(subItem, "\"");
|
|
1442
|
-
} else {
|
|
1443
|
-
return "\"(ao-type-float) ".concat(formatFloat(subItem), "\"");
|
|
1444
|
-
}
|
|
1445
|
-
} else if (typeof subItem === "string") {
|
|
1446
|
-
return "\"".concat(subItem, "\"");
|
|
1447
|
-
} else if (subItem === null) {
|
|
1448
|
-
return "\"(ao-type-atom) \\\"null\\\"\"";
|
|
1449
|
-
} else if (subItem === undefined) {
|
|
1450
|
-
return "\"(ao-type-atom) \\\"undefined\\\"\"";
|
|
1451
|
-
} else if (_typeof(subItem) === "symbol") {
|
|
1452
|
-
var desc = subItem.description || "Symbol.for()";
|
|
1453
|
-
return "\"(ao-type-atom) \\\"".concat(desc, "\\\"\"");
|
|
1454
|
-
} else if (typeof subItem === "boolean") {
|
|
1455
|
-
return "\"(ao-type-atom) \\\"".concat(subItem, "\\\"\"");
|
|
1456
|
-
} else if (Array.isArray(subItem)) {
|
|
1457
|
-
// Use the full encodeArrayItem for nested arrays
|
|
1458
|
-
return encodeArrayItem(subItem);
|
|
1459
|
-
} else if (isBytes(subItem)) {
|
|
1460
|
-
var _buffer2 = toBuffer(subItem);
|
|
1461
|
-
if (_buffer2.length === 0 || _buffer2.byteLength === 0) {
|
|
1462
|
-
return "\"\"";
|
|
1463
|
-
}
|
|
1464
|
-
return "\"(ao-type-binary)\"";
|
|
1465
|
-
} else if (isPojo(subItem)) {
|
|
1466
|
-
var json = JSON.stringify(subItem);
|
|
1467
|
-
var escaped = json.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
1468
|
-
return "\"(ao-type-map) ".concat(escaped, "\"");
|
|
1469
|
-
} else {
|
|
1470
|
-
return "\"".concat(String(subItem), "\"");
|
|
1471
|
-
}
|
|
1472
|
-
}).join(", ");
|
|
1473
|
-
fieldLines.push("".concat(index, ": ").concat(encodedItems));
|
|
1474
|
-
}
|
|
1475
|
-
} else if (typeof item === "number") {
|
|
1476
|
-
if (Number.isInteger(item)) {
|
|
1477
|
-
partTypes.push("".concat(index, "=\"integer\""));
|
|
1478
|
-
fieldLines.push("".concat(index, ": ").concat(item));
|
|
1479
|
-
} else {
|
|
1480
|
-
partTypes.push("".concat(index, "=\"float\""));
|
|
1481
|
-
fieldLines.push("".concat(index, ": ").concat(formatFloat(item)));
|
|
1482
|
-
}
|
|
1483
|
-
} else if (typeof item === "string") {
|
|
1484
|
-
// Non-empty strings just get field lines, no type annotation
|
|
1485
|
-
fieldLines.push("".concat(index, ": ").concat(item));
|
|
1486
|
-
} else if (item === null || item === undefined || _typeof(item) === "symbol" || typeof item === "boolean") {
|
|
1487
|
-
partTypes.push("".concat(index, "=\"atom\""));
|
|
1488
|
-
if (item === null) {
|
|
1489
|
-
fieldLines.push("".concat(index, ": null"));
|
|
1490
|
-
} else if (item === undefined) {
|
|
1491
|
-
fieldLines.push("".concat(index, ": undefined"));
|
|
1492
|
-
} else if (_typeof(item) === "symbol") {
|
|
1493
|
-
var desc = item.description || "Symbol.for()";
|
|
1494
|
-
fieldLines.push("".concat(index, ": ").concat(desc));
|
|
1495
|
-
} else {
|
|
1496
|
-
fieldLines.push("".concat(index, ": ").concat(item));
|
|
1497
|
-
}
|
|
1498
|
-
} else if (isBytes(item)) {
|
|
1499
|
-
var _buffer3 = toBuffer(item);
|
|
1500
|
-
if (_buffer3.length === 0) {
|
|
1501
|
-
partTypes.push("".concat(index, "=\"empty-binary\""));
|
|
1502
|
-
} else {
|
|
1503
|
-
partTypes.push("".concat(index, "=\"binary\""));
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
});
|
|
1507
|
-
_isInline2 = bodyKey === "body" && headers["inline-body-key"] === "body";
|
|
1508
|
-
if (_isInline2) {
|
|
1509
|
-
_orderedLines2 = [];
|
|
1510
|
-
if (partTypes.length > 0) {
|
|
1511
|
-
_orderedLines2.push("ao-types: ".concat(partTypes.sort(function (a, b) {
|
|
1512
|
-
var aNum = parseInt(a.split("=")[0]);
|
|
1513
|
-
var bNum = parseInt(b.split("=")[0]);
|
|
1514
|
-
return aNum - bNum;
|
|
1515
|
-
}).join(", ")));
|
|
1516
|
-
}
|
|
1517
|
-
_orderedLines2.push("content-disposition: inline");
|
|
1518
|
-
if (fieldLines.length > 0) {
|
|
1519
|
-
_orderedLines2.push("");
|
|
1520
|
-
_iterator6 = _createForOfIteratorHelper(fieldLines);
|
|
1521
|
-
try {
|
|
1522
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1523
|
-
line = _step6.value;
|
|
1524
|
-
_orderedLines2.push(line);
|
|
1525
|
-
}
|
|
1526
|
-
} catch (err) {
|
|
1527
|
-
_iterator6.e(err);
|
|
1528
|
-
} finally {
|
|
1529
|
-
_iterator6.f();
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
bodyParts.push(new Blob([_orderedLines2.join("\r\n") + "\r\n"]));
|
|
1533
|
-
} else {
|
|
1534
|
-
// Put ao-types first, then content-disposition, then field lines
|
|
1535
|
-
_orderedLines3 = [];
|
|
1536
|
-
if (partTypes.length > 0) {
|
|
1537
|
-
_orderedLines3.push("ao-types: ".concat(partTypes.sort(function (a, b) {
|
|
1538
|
-
var aNum = parseInt(a.split("=")[0]);
|
|
1539
|
-
var bNum = parseInt(b.split("=")[0]);
|
|
1540
|
-
return aNum - bNum;
|
|
1541
|
-
}).join(", ")));
|
|
1542
|
-
}
|
|
1543
|
-
_orderedLines3.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
1544
|
-
|
|
1545
|
-
// Add field lines directly without blank line
|
|
1546
|
-
_iterator7 = _createForOfIteratorHelper(fieldLines);
|
|
1547
|
-
try {
|
|
1548
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1549
|
-
_line = _step7.value;
|
|
1550
|
-
_orderedLines3.push(_line);
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
// Add trailing blank line if we have field lines
|
|
1554
|
-
} catch (err) {
|
|
1555
|
-
_iterator7.e(err);
|
|
1556
|
-
} finally {
|
|
1557
|
-
_iterator7.f();
|
|
1558
|
-
}
|
|
1559
|
-
if (fieldLines.length > 0) {
|
|
1560
|
-
bodyParts.push(new Blob([_orderedLines3.join("\r\n") + "\r\n"]));
|
|
1561
|
-
} else {
|
|
1562
|
-
bodyParts.push(new Blob([_orderedLines3.join("\r\n")]));
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
return _context5.abrupt("return", 0);
|
|
1566
|
-
case 52:
|
|
1567
|
-
// This should not be reached for binary values as they're handled above
|
|
1568
|
-
isInline = bodyKey === "body" && headers["inline-body-key"] === "body";
|
|
1569
|
-
if (isInline) {
|
|
1570
|
-
lines.push("content-disposition: inline");
|
|
1571
|
-
} else {
|
|
1572
|
-
lines.push("content-disposition: form-data;name=\"".concat(bodyKey, "\""));
|
|
1573
|
-
}
|
|
1574
|
-
if (typeof value === "string") {
|
|
1575
|
-
lines.push("");
|
|
1576
|
-
lines.push(value);
|
|
1577
|
-
bodyParts.push(new Blob([lines.join("\r\n")]));
|
|
1578
|
-
} else if (typeof value === "boolean" || typeof value === "number" || value === null || value === undefined || _typeof(value) === "symbol") {
|
|
1579
|
-
if (typeof value === "boolean") {
|
|
1580
|
-
content = "\"".concat(value, "\"");
|
|
1581
|
-
} else if (typeof value === "number") {
|
|
1582
|
-
content = String(value);
|
|
1583
|
-
} else if (value === null) {
|
|
1584
|
-
content = '"null"';
|
|
1585
|
-
} else if (value === undefined) {
|
|
1586
|
-
content = '"undefined"';
|
|
1587
|
-
} else if (_typeof(value) === "symbol") {
|
|
1588
|
-
content = "\"".concat(value.description || "Symbol.for()", "\"");
|
|
1589
|
-
}
|
|
1590
|
-
lines.push("");
|
|
1591
|
-
lines.push(content);
|
|
1592
|
-
bodyParts.push(new Blob([lines.join("\r\n")]));
|
|
1593
|
-
}
|
|
1594
|
-
case 55:
|
|
1595
|
-
case "end":
|
|
1596
|
-
return _context5.stop();
|
|
1597
|
-
}
|
|
1598
|
-
}, _loop5);
|
|
1599
|
-
});
|
|
1600
|
-
_iterator5.s();
|
|
1601
|
-
case 126:
|
|
1602
|
-
if ((_step5 = _iterator5.n()).done) {
|
|
1603
|
-
_context6.next = 133;
|
|
1604
|
-
break;
|
|
1605
|
-
}
|
|
1606
|
-
return _context6.delegateYield(_loop5(), "t2", 128);
|
|
1607
|
-
case 128:
|
|
1608
|
-
_ret = _context6.t2;
|
|
1609
|
-
if (!(_ret === 0)) {
|
|
1610
|
-
_context6.next = 131;
|
|
1611
|
-
break;
|
|
1612
|
-
}
|
|
1613
|
-
return _context6.abrupt("continue", 131);
|
|
1614
|
-
case 131:
|
|
1615
|
-
_context6.next = 126;
|
|
1616
|
-
break;
|
|
1617
|
-
case 133:
|
|
1618
|
-
_context6.next = 138;
|
|
1619
|
-
break;
|
|
1620
|
-
case 135:
|
|
1621
|
-
_context6.prev = 135;
|
|
1622
|
-
_context6.t3 = _context6["catch"](123);
|
|
1623
|
-
_iterator5.e(_context6.t3);
|
|
1624
|
-
case 138:
|
|
1625
|
-
_context6.prev = 138;
|
|
1626
|
-
_iterator5.f();
|
|
1627
|
-
return _context6.finish(138);
|
|
1628
|
-
case 141:
|
|
1629
|
-
// Add the special data/body part if needed
|
|
1630
|
-
if (hasSpecialDataBody && obj.data && obj.data.body && isBytes(obj.data.body)) {
|
|
1631
|
-
buffer = toBuffer(obj.data.body);
|
|
1632
|
-
specialPart = ["content-disposition: form-data;name=\"data/body\"", "", ""].join("\r\n");
|
|
1633
|
-
bodyParts.push(new Blob([specialPart, buffer]));
|
|
1634
|
-
}
|
|
1635
|
-
_context6.next = 144;
|
|
1636
|
-
return Promise.all(bodyParts.map(function (part) {
|
|
1637
|
-
return part.text();
|
|
1638
|
-
}));
|
|
1639
|
-
case 144:
|
|
1640
|
-
partsContent = _context6.sent;
|
|
1641
|
-
allContent = partsContent.join("");
|
|
1642
|
-
_context6.next = 148;
|
|
1643
|
-
return sha256(new TextEncoder().encode(allContent));
|
|
1644
|
-
case 148:
|
|
1645
|
-
boundaryHash = _context6.sent;
|
|
1646
|
-
boundary = _base64url["default"].encode(Buffer.from(boundaryHash));
|
|
1647
|
-
finalParts = [];
|
|
1648
|
-
for (i = 0; i < bodyParts.length; i++) {
|
|
1649
|
-
if (i === 0) {
|
|
1650
|
-
finalParts.push(new Blob(["--".concat(boundary, "\r\n")]));
|
|
1651
|
-
} else {
|
|
1652
|
-
finalParts.push(new Blob(["\r\n--".concat(boundary, "\r\n")]));
|
|
1653
|
-
}
|
|
1654
|
-
finalParts.push(bodyParts[i]);
|
|
1655
|
-
}
|
|
1656
|
-
finalParts.push(new Blob(["\r\n--".concat(boundary, "--")]));
|
|
1657
|
-
headers["content-type"] = "multipart/form-data; boundary=\"".concat(boundary, "\"");
|
|
1658
|
-
body = new Blob(finalParts);
|
|
1659
|
-
_context6.next = 157;
|
|
1660
|
-
return body.arrayBuffer();
|
|
1661
|
-
case 157:
|
|
1662
|
-
finalContent = _context6.sent;
|
|
1663
|
-
if (!(finalContent.byteLength > 0)) {
|
|
1664
|
-
_context6.next = 164;
|
|
1665
|
-
break;
|
|
1666
|
-
}
|
|
1667
|
-
_context6.next = 161;
|
|
1668
|
-
return sha256(finalContent);
|
|
1669
|
-
case 161:
|
|
1670
|
-
_contentDigest5 = _context6.sent;
|
|
1671
|
-
_base5 = _base64url["default"].toBase64(_base64url["default"].encode(_contentDigest5));
|
|
1672
|
-
headers["content-digest"] = "sha-256=:".concat(_base5, ":");
|
|
1673
|
-
case 164:
|
|
1674
|
-
headers["content-length"] = String(finalContent.byteLength);
|
|
1675
|
-
console.log("=== ENCODE END ===\n");
|
|
1676
|
-
return _context6.abrupt("return", {
|
|
1317
|
+
// Step 18: Return result
|
|
1318
|
+
return _context8.abrupt("return", {
|
|
1677
1319
|
headers: headers,
|
|
1678
1320
|
body: body
|
|
1679
1321
|
});
|
|
1680
|
-
case
|
|
1322
|
+
case 58:
|
|
1681
1323
|
case "end":
|
|
1682
|
-
return
|
|
1324
|
+
return _context8.stop();
|
|
1683
1325
|
}
|
|
1684
|
-
},
|
|
1326
|
+
}, _callee8);
|
|
1685
1327
|
}));
|
|
1686
1328
|
return _encode.apply(this, arguments);
|
|
1687
1329
|
}
|
|
1688
|
-
function enc(
|
|
1330
|
+
function enc(_x11) {
|
|
1689
1331
|
return _enc.apply(this, arguments);
|
|
1690
1332
|
}
|
|
1691
1333
|
function _enc() {
|
|
1692
|
-
_enc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1693
|
-
return _regeneratorRuntime().wrap(function
|
|
1694
|
-
while (1) switch (
|
|
1334
|
+
_enc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fields) {
|
|
1335
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1336
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1695
1337
|
case 0:
|
|
1696
|
-
|
|
1338
|
+
_context9.next = 2;
|
|
1697
1339
|
return encode(fields);
|
|
1698
1340
|
case 2:
|
|
1699
|
-
return
|
|
1341
|
+
return _context9.abrupt("return", _context9.sent);
|
|
1700
1342
|
case 3:
|
|
1701
1343
|
case "end":
|
|
1702
|
-
return
|
|
1344
|
+
return _context9.stop();
|
|
1703
1345
|
}
|
|
1704
|
-
},
|
|
1346
|
+
}, _callee9);
|
|
1705
1347
|
}));
|
|
1706
1348
|
return _enc.apply(this, arguments);
|
|
1707
1349
|
}
|