wao 0.26.1 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/encode.js ADDED
@@ -0,0 +1,1047 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.enc = enc;
7
+ var _base64url = _interopRequireDefault(require("base64url"));
8
+ var _fastSha = require("fast-sha256");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
+ 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; } } }; }
11
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
12
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
13
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
14
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
15
+ 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."); }
16
+ 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; } }
17
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
18
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
20
+ 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); }
21
+ function isBytes(value) {
22
+ return value instanceof ArrayBuffer || ArrayBuffer.isView(value) || Buffer.isBuffer(value);
23
+ }
24
+ function isPojo(value) {
25
+ return !isBytes(value) && !Array.isArray(value) && !(value instanceof Blob) && _typeof(value) === "object" && value !== null;
26
+ }
27
+ function hbEncodeValue(value) {
28
+ if (isBytes(value)) {
29
+ var length = value.byteLength || value.length || 0;
30
+ if (length === 0) return ["empty-binary", ""];
31
+ return [undefined, value];
32
+ }
33
+ if (typeof value === "string") {
34
+ if (value.length === 0) return ["empty-string", ""];
35
+ return [undefined, value];
36
+ }
37
+ if (Array.isArray(value)) {
38
+ if (value.length === 0) return ["empty-list", "[]"];
39
+ var hasObjects = value.some(function (item) {
40
+ return isPojo(item);
41
+ });
42
+ if (hasObjects) {
43
+ return ["list_with_objects", value];
44
+ }
45
+ var items = value.map(function (item) {
46
+ if (typeof item === "string") {
47
+ return "\"".concat(item, "\"");
48
+ } else if (typeof item === "number") {
49
+ if (Number.isInteger(item)) {
50
+ return "\"(ao-type-integer) ".concat(item, "\"");
51
+ } else {
52
+ return "\"(ao-type-float) ".concat(item.toExponential(20).replace("e+0", "e+00"), "\"");
53
+ }
54
+ } else if (typeof item === "boolean") {
55
+ return "\"(ao-type-atom) \\\"".concat(item ? "true" : "false", "\\\"\"");
56
+ } else if (_typeof(item) === "symbol") {
57
+ var desc = item.description || "symbol";
58
+ return "\"(ao-type-atom) \\\"".concat(desc, "\\\"\"");
59
+ } else if (item === null) {
60
+ return "\"(ao-type-atom) \\\"null\\\"\"";
61
+ } else if (item === undefined) {
62
+ return "\"(ao-type-atom) \\\"undefined\\\"\"";
63
+ } else if (isBytes(item)) {
64
+ var _length = item.byteLength || item.length || 0;
65
+ if (_length === 0) {
66
+ return "\"\"";
67
+ } else {
68
+ var base64 = _base64url["default"].encode(Buffer.from(item));
69
+ return "\"(ao-type-binary) ".concat(base64, "\"");
70
+ }
71
+ } else if (Array.isArray(item)) {
72
+ var _hbEncodeValue = hbEncodeValue(item),
73
+ _hbEncodeValue2 = _slicedToArray(_hbEncodeValue, 2),
74
+ encoded = _hbEncodeValue2[1];
75
+ var escapedEncoded = encoded.replace(/"/g, '\\"');
76
+ return "\"(ao-type-list) ".concat(escapedEncoded, "\"");
77
+ } else {
78
+ return "\"".concat(String(item), "\"");
79
+ }
80
+ });
81
+ return ["list", items.join(", ")];
82
+ }
83
+ if (typeof value === "number") {
84
+ if (!Number.isInteger(value)) return ["float", "".concat(value)];
85
+ return ["integer", String(value)];
86
+ }
87
+ if (typeof value === "boolean") {
88
+ return ["atom", value ? "true" : "false"];
89
+ }
90
+ if (_typeof(value) === "symbol") {
91
+ var desc = value.description || "symbol";
92
+ return ["atom", desc];
93
+ }
94
+ if (value === null) return ["atom", "null"];
95
+ if (value === undefined) return ["atom", "undefined"];
96
+ if (isPojo(value)) {
97
+ throw new Error("Objects must be lifted");
98
+ }
99
+ throw new Error("Cannot encode value: ".concat(String(value)));
100
+ }
101
+ var MAX_HEADER_LENGTH = 4096;
102
+ function encode_body_keys(bodyKeys) {
103
+ if (!bodyKeys || bodyKeys.length === 0) return "";
104
+ var items = bodyKeys.map(function (key) {
105
+ var escaped = key.replace(/"/g, '\\"');
106
+ return "\"".concat(escaped, "\"");
107
+ });
108
+ return items.join(", ");
109
+ }
110
+ function hasNewline(_x) {
111
+ return _hasNewline.apply(this, arguments);
112
+ }
113
+ function _hasNewline() {
114
+ _hasNewline = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(value) {
115
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
116
+ while (1) switch (_context.prev = _context.next) {
117
+ case 0:
118
+ if (!(typeof value === "string")) {
119
+ _context.next = 2;
120
+ break;
121
+ }
122
+ return _context.abrupt("return", value.includes("\n"));
123
+ case 2:
124
+ if (!(value instanceof Blob)) {
125
+ _context.next = 7;
126
+ break;
127
+ }
128
+ _context.next = 5;
129
+ return value.text();
130
+ case 5:
131
+ value = _context.sent;
132
+ return _context.abrupt("return", value.includes("\n"));
133
+ case 7:
134
+ if (!isBytes(value)) {
135
+ _context.next = 9;
136
+ break;
137
+ }
138
+ return _context.abrupt("return", Buffer.from(value).includes("\n"));
139
+ case 9:
140
+ return _context.abrupt("return", false);
141
+ case 10:
142
+ case "end":
143
+ return _context.stop();
144
+ }
145
+ }, _callee);
146
+ }));
147
+ return _hasNewline.apply(this, arguments);
148
+ }
149
+ function sha256(_x2) {
150
+ return _sha.apply(this, arguments);
151
+ }
152
+ function _sha() {
153
+ _sha = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
154
+ var uint8Array, hashResult;
155
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
156
+ while (1) switch (_context2.prev = _context2.next) {
157
+ case 0:
158
+ if (!(data instanceof ArrayBuffer)) {
159
+ _context2.next = 4;
160
+ break;
161
+ }
162
+ uint8Array = new Uint8Array(data);
163
+ _context2.next = 13;
164
+ break;
165
+ case 4:
166
+ if (!(data instanceof Uint8Array)) {
167
+ _context2.next = 8;
168
+ break;
169
+ }
170
+ uint8Array = data;
171
+ _context2.next = 13;
172
+ break;
173
+ case 8:
174
+ if (!ArrayBuffer.isView(data)) {
175
+ _context2.next = 12;
176
+ break;
177
+ }
178
+ uint8Array = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
179
+ _context2.next = 13;
180
+ break;
181
+ case 12:
182
+ throw new Error("sha256 expects ArrayBuffer or ArrayBufferView");
183
+ case 13:
184
+ hashResult = (0, _fastSha.hash)(uint8Array);
185
+ return _context2.abrupt("return", hashResult.buffer.slice(hashResult.byteOffset, hashResult.byteOffset + hashResult.byteLength));
186
+ case 15:
187
+ case "end":
188
+ return _context2.stop();
189
+ }
190
+ }, _callee2);
191
+ }));
192
+ return _sha.apply(this, arguments);
193
+ }
194
+ function collectParts(obj) {
195
+ var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
196
+ var parts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
197
+ var types = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
198
+ var _loop = function _loop() {
199
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
200
+ key = _Object$entries$_i[0],
201
+ value = _Object$entries$_i[1];
202
+ var currentPath = path ? "".concat(path, "/").concat(key) : key;
203
+ if (value === null || value === undefined) {
204
+ if (!parts[path]) parts[path] = {};
205
+ parts[path][key] = value === null ? '"null"' : '"undefined"';
206
+ types[currentPath] = "atom";
207
+ } else if (isBytes(value)) {
208
+ if (!parts[path]) parts[path] = {};
209
+ parts[path][key] = value;
210
+ var length = value.byteLength || value.length || 0;
211
+ if (length === 0) {
212
+ types[currentPath] = "empty-binary";
213
+ }
214
+ } else if (typeof value === "string") {
215
+ if (value.length === 0) {
216
+ types[currentPath] = "empty-binary";
217
+ if (!parts[path]) parts[path] = {};
218
+ parts[path][key] = "";
219
+ } else {
220
+ if (!parts[path]) parts[path] = {};
221
+ parts[path][key] = value;
222
+ }
223
+ } else if (Array.isArray(value)) {
224
+ if (value.length === 0) {
225
+ types[currentPath] = "empty-list";
226
+ if (!parts[path]) parts[path] = {};
227
+ parts[path][key] = "[]";
228
+ } else {
229
+ var hasObjects = value.some(function (item) {
230
+ return isPojo(item);
231
+ });
232
+ if (hasObjects) {
233
+ // Arrays with objects: create separate parts for each indexed item
234
+ types[currentPath] = "list";
235
+ value.forEach(function (item, index) {
236
+ var indexKey = String(index + 1);
237
+ var indexPath = "".concat(currentPath, "/").concat(indexKey);
238
+ if (isPojo(item)) {
239
+ // Each object in the array becomes a separate part
240
+ if (!parts[indexPath]) parts[indexPath] = {};
241
+ for (var _i2 = 0, _Object$entries2 = Object.entries(item); _i2 < _Object$entries2.length; _i2++) {
242
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
243
+ objKey = _Object$entries2$_i[0],
244
+ objValue = _Object$entries2$_i[1];
245
+ parts[indexPath][objKey] = objValue;
246
+
247
+ // Set types for object fields
248
+ var fieldPath = "".concat(indexPath, "/").concat(objKey);
249
+ if (typeof objValue === "number") {
250
+ types[fieldPath] = Number.isInteger(objValue) ? "integer" : "float";
251
+ } else if (typeof objValue === "boolean") {
252
+ types[fieldPath] = "atom";
253
+ } else if (_typeof(objValue) === "symbol") {
254
+ types[fieldPath] = "atom";
255
+ // Store the symbol's description for later use
256
+ parts[indexPath][objKey] = objValue;
257
+ } else if (typeof objValue === "string" && objValue.length === 0) {
258
+ types[fieldPath] = "empty-binary";
259
+ } else if (Array.isArray(objValue) && objValue.length === 0) {
260
+ types[fieldPath] = "empty-list";
261
+ } else if (isPojo(objValue) && Object.keys(objValue).length === 0) {
262
+ types[fieldPath] = "empty-message";
263
+ }
264
+ }
265
+ } else {
266
+ // Non-object items in the array
267
+ if (!parts[currentPath]) parts[currentPath] = {};
268
+ parts[currentPath][indexKey] = item;
269
+ if (typeof item === "number") {
270
+ types["".concat(currentPath, "/").concat(indexKey)] = Number.isInteger(item) ? "integer" : "float";
271
+ } else if (typeof item === "boolean") {
272
+ types["".concat(currentPath, "/").concat(indexKey)] = "atom";
273
+ }
274
+ }
275
+ });
276
+ } else {
277
+ // Simple arrays without objects
278
+ var _hbEncodeValue3 = hbEncodeValue(value),
279
+ _hbEncodeValue4 = _slicedToArray(_hbEncodeValue3, 2),
280
+ type = _hbEncodeValue4[0],
281
+ encoded = _hbEncodeValue4[1];
282
+ if (!parts[path]) parts[path] = {};
283
+ parts[path][key] = encoded;
284
+ types[currentPath] = type || "list";
285
+ }
286
+ }
287
+ } else if (isPojo(value)) {
288
+ if (Object.keys(value).length === 0) {
289
+ types[currentPath] = "empty-message";
290
+ if (!parts[path]) parts[path] = {};
291
+ parts[path][key] = "{}";
292
+ } else {
293
+ var hasOnlyEmptyChildren = Object.entries(value).every(function (_ref) {
294
+ var _ref2 = _slicedToArray(_ref, 2),
295
+ k = _ref2[0],
296
+ v = _ref2[1];
297
+ return Array.isArray(v) && v.length === 0 || isPojo(v) && Object.keys(v).length === 0;
298
+ });
299
+ if (hasOnlyEmptyChildren) {
300
+ if (!parts[currentPath]) parts[currentPath] = {};
301
+ }
302
+ collectParts(value, currentPath, parts, types);
303
+ }
304
+ } else if (_typeof(value) === "symbol") {
305
+ if (!parts[path]) parts[path] = {};
306
+ parts[path][key] = value.description || "symbol";
307
+ types[currentPath] = "atom";
308
+ } else if (typeof value === "boolean") {
309
+ if (!parts[path]) parts[path] = {};
310
+ parts[path][key] = value;
311
+ types[currentPath] = "atom";
312
+ } else {
313
+ if (!parts[path]) parts[path] = {};
314
+ parts[path][key] = value;
315
+ if (typeof value === "number") {
316
+ types[currentPath] = Number.isInteger(value) ? "integer" : "float";
317
+ }
318
+ }
319
+ };
320
+ for (var _i = 0, _Object$entries = Object.entries(obj); _i < _Object$entries.length; _i++) {
321
+ _loop();
322
+ }
323
+ return {
324
+ parts: parts,
325
+ types: types
326
+ };
327
+ }
328
+ function encode() {
329
+ return _encode.apply(this, arguments);
330
+ }
331
+ function _encode() {
332
+ _encode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
333
+ var obj,
334
+ objKeys,
335
+ fieldName,
336
+ binaryData,
337
+ headers,
338
+ bodyBuffer,
339
+ bodyArrayBuffer,
340
+ contentDigest,
341
+ base64,
342
+ _headers,
343
+ types,
344
+ needsMultipart,
345
+ _i3,
346
+ _Object$entries3,
347
+ _Object$entries3$_i,
348
+ key,
349
+ value,
350
+ _hbEncodeValue5,
351
+ _hbEncodeValue6,
352
+ type,
353
+ encoded,
354
+ body,
355
+ _bodyBuffer,
356
+ _bodyArrayBuffer,
357
+ _contentDigest,
358
+ _base,
359
+ _args3 = arguments;
360
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
361
+ while (1) switch (_context3.prev = _context3.next) {
362
+ case 0:
363
+ obj = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
364
+ console.log("[encode] START with obj:", JSON.stringify(obj));
365
+ if (!(Object.keys(obj).length === 0)) {
366
+ _context3.next = 4;
367
+ break;
368
+ }
369
+ return _context3.abrupt("return", {
370
+ headers: {},
371
+ body: undefined
372
+ });
373
+ case 4:
374
+ // Check if we have a simple binary field
375
+ objKeys = Object.keys(obj);
376
+ if (!(objKeys.length === 1 && isBytes(obj[objKeys[0]]))) {
377
+ _context3.next = 18;
378
+ break;
379
+ }
380
+ // Single binary field - return it directly
381
+ fieldName = objKeys[0];
382
+ binaryData = obj[fieldName];
383
+ headers = {};
384
+ bodyBuffer = Buffer.isBuffer(binaryData) ? binaryData : Buffer.from(binaryData);
385
+ bodyArrayBuffer = bodyBuffer.buffer.slice(bodyBuffer.byteOffset, bodyBuffer.byteOffset + bodyBuffer.byteLength);
386
+ _context3.next = 13;
387
+ return sha256(bodyArrayBuffer);
388
+ case 13:
389
+ contentDigest = _context3.sent;
390
+ base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
391
+ headers["content-digest"] = "sha-256=:".concat(base64, ":");
392
+ console.log("[encode] FINAL (simple binary field) - headers:", headers, "body:", binaryData);
393
+ return _context3.abrupt("return", {
394
+ headers: headers,
395
+ body: binaryData
396
+ });
397
+ case 18:
398
+ if (!("body" in obj && isBytes(obj.body))) {
399
+ _context3.next = 108;
400
+ break;
401
+ }
402
+ _headers = {};
403
+ types = [];
404
+ needsMultipart = false;
405
+ _i3 = 0, _Object$entries3 = Object.entries(obj);
406
+ case 23:
407
+ if (!(_i3 < _Object$entries3.length)) {
408
+ _context3.next = 95;
409
+ break;
410
+ }
411
+ _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2), key = _Object$entries3$_i[0], value = _Object$entries3$_i[1];
412
+ if (!(key === "body")) {
413
+ _context3.next = 27;
414
+ break;
415
+ }
416
+ return _context3.abrupt("continue", 92);
417
+ case 27:
418
+ if (!(value === null)) {
419
+ _context3.next = 32;
420
+ break;
421
+ }
422
+ _headers[key] = "null";
423
+ types.push("".concat(key, "=\"atom\""));
424
+ _context3.next = 92;
425
+ break;
426
+ case 32:
427
+ if (!(value === undefined)) {
428
+ _context3.next = 37;
429
+ break;
430
+ }
431
+ _headers[key] = "undefined";
432
+ types.push("".concat(key, "=\"atom\""));
433
+ _context3.next = 92;
434
+ break;
435
+ case 37:
436
+ if (!(typeof value === "string" && value.length === 0)) {
437
+ _context3.next = 41;
438
+ break;
439
+ }
440
+ types.push("".concat(key, "=\"empty-binary\""));
441
+ _context3.next = 92;
442
+ break;
443
+ case 41:
444
+ if (!Array.isArray(value)) {
445
+ _context3.next = 57;
446
+ break;
447
+ }
448
+ if (!(value.length === 0)) {
449
+ _context3.next = 46;
450
+ break;
451
+ }
452
+ types.push("".concat(key, "=\"empty-list\""));
453
+ _context3.next = 55;
454
+ break;
455
+ case 46:
456
+ if (!value.some(function (item) {
457
+ return isPojo(item);
458
+ })) {
459
+ _context3.next = 52;
460
+ break;
461
+ }
462
+ // Arrays with objects need multipart
463
+ types.push("".concat(key, "=\"list\""));
464
+ needsMultipart = true;
465
+ return _context3.abrupt("break", 95);
466
+ case 52:
467
+ _hbEncodeValue5 = hbEncodeValue(value), _hbEncodeValue6 = _slicedToArray(_hbEncodeValue5, 2), type = _hbEncodeValue6[0], encoded = _hbEncodeValue6[1];
468
+ _headers[key] = encoded;
469
+ types.push("".concat(key, "=\"").concat(type, "\""));
470
+ case 55:
471
+ _context3.next = 92;
472
+ break;
473
+ case 57:
474
+ if (!isBytes(value)) {
475
+ _context3.next = 66;
476
+ break;
477
+ }
478
+ if (!(value.length === 0 || value.byteLength === 0)) {
479
+ _context3.next = 62;
480
+ break;
481
+ }
482
+ types.push("".concat(key, "=\"empty-binary\""));
483
+ _context3.next = 64;
484
+ break;
485
+ case 62:
486
+ needsMultipart = true;
487
+ return _context3.abrupt("break", 95);
488
+ case 64:
489
+ _context3.next = 92;
490
+ break;
491
+ case 66:
492
+ if (!(typeof value === "boolean")) {
493
+ _context3.next = 71;
494
+ break;
495
+ }
496
+ _headers[key] = "\"".concat(value, "\"");
497
+ types.push("".concat(key, "=\"atom\""));
498
+ _context3.next = 92;
499
+ break;
500
+ case 71:
501
+ if (!(_typeof(value) === "symbol")) {
502
+ _context3.next = 76;
503
+ break;
504
+ }
505
+ _headers[key] = value.description || "symbol";
506
+ types.push("".concat(key, "=\"atom\""));
507
+ _context3.next = 92;
508
+ break;
509
+ case 76:
510
+ if (!(typeof value === "number")) {
511
+ _context3.next = 81;
512
+ break;
513
+ }
514
+ _headers[key] = String(value);
515
+ types.push("".concat(key, "=\"").concat(Number.isInteger(value) ? "integer" : "float", "\""));
516
+ _context3.next = 92;
517
+ break;
518
+ case 81:
519
+ if (!(typeof value === "string")) {
520
+ _context3.next = 85;
521
+ break;
522
+ }
523
+ _headers[key] = value;
524
+ _context3.next = 92;
525
+ break;
526
+ case 85:
527
+ if (!(isPojo(value) && Object.keys(value).length === 0)) {
528
+ _context3.next = 89;
529
+ break;
530
+ }
531
+ types.push("".concat(key, "=\"empty-message\""));
532
+ _context3.next = 92;
533
+ break;
534
+ case 89:
535
+ if (!isPojo(value)) {
536
+ _context3.next = 92;
537
+ break;
538
+ }
539
+ needsMultipart = true;
540
+ return _context3.abrupt("break", 95);
541
+ case 92:
542
+ _i3++;
543
+ _context3.next = 23;
544
+ break;
545
+ case 95:
546
+ if (!needsMultipart) {
547
+ _context3.next = 97;
548
+ break;
549
+ }
550
+ return _context3.abrupt("return", encodeMultipart(obj));
551
+ case 97:
552
+ if (types.length > 0) {
553
+ _headers["ao-types"] = types.sort().join(", ");
554
+ }
555
+ body = obj.body;
556
+ _bodyBuffer = Buffer.isBuffer(body) ? body : Buffer.from(body);
557
+ _bodyArrayBuffer = _bodyBuffer.buffer.slice(_bodyBuffer.byteOffset, _bodyBuffer.byteOffset + _bodyBuffer.byteLength);
558
+ _context3.next = 103;
559
+ return sha256(_bodyArrayBuffer);
560
+ case 103:
561
+ _contentDigest = _context3.sent;
562
+ _base = _base64url["default"].toBase64(_base64url["default"].encode(_contentDigest));
563
+ _headers["content-digest"] = "sha-256=:".concat(_base, ":");
564
+ console.log("[encode] FINAL (simple body encoding) - headers:", _headers, "body:", body);
565
+ return _context3.abrupt("return", {
566
+ headers: _headers,
567
+ body: body
568
+ });
569
+ case 108:
570
+ return _context3.abrupt("return", encodeMultipart(obj));
571
+ case 109:
572
+ case "end":
573
+ return _context3.stop();
574
+ }
575
+ }, _callee3);
576
+ }));
577
+ return _encode.apply(this, arguments);
578
+ }
579
+ function encodeMultipart(_x3) {
580
+ return _encodeMultipart.apply(this, arguments);
581
+ }
582
+ function _encodeMultipart() {
583
+ _encodeMultipart = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(obj) {
584
+ var _collectParts, parts, types, headers, bodyParts, bodyKeys, headerTypes, _i4, _Object$entries4, _Object$entries4$_i, key, value, _i5, _Object$entries5, _Object$entries5$_i, path, content, _i6, _Object$entries6, _Object$entries6$_i, _key, _value, length, valueStr, type, _i7, _Object$entries7, _Object$entries7$_i, _key2, _value2, _type, _i8, _Object$entries8, _Object$entries8$_i, _key3, _type2, inlineKey, _iterator, _step, _path, fieldValue, headerStr, headerBlob, dataBlob, _lines, _isInlineKey, _type3, _content, lines, binaryParts, isInlineKey, sortedKeys, partTypes, _iterator3, _step3, _key4, fullPath, _type4, _iterator4, _step4, _key5, _value3, _fullPath, _type5, symbolValue, allParts, _iterator5, _step5, binaryPart, partsForBoundary, _iterator2, _step2, part, partContent, allPartsContent, allPartsBuffer, hashResult, boundary, finalParts, i, body, finalContent, contentDigest, base64;
585
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
586
+ while (1) switch (_context4.prev = _context4.next) {
587
+ case 0:
588
+ _collectParts = collectParts(obj), parts = _collectParts.parts, types = _collectParts.types;
589
+ console.log("[encode] Parts:", parts, "Types:", types);
590
+ headers = {};
591
+ bodyParts = [];
592
+ bodyKeys = []; // Collect header types for arrays with objects
593
+ headerTypes = [];
594
+ for (_i4 = 0, _Object$entries4 = Object.entries(obj); _i4 < _Object$entries4.length; _i4++) {
595
+ _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2), key = _Object$entries4$_i[0], value = _Object$entries4$_i[1];
596
+ if (Array.isArray(value) && value.some(function (item) {
597
+ return isPojo(item);
598
+ })) {
599
+ headerTypes.push("".concat(key, "=\"list\""));
600
+ }
601
+ }
602
+ _i5 = 0, _Object$entries5 = Object.entries(parts);
603
+ case 8:
604
+ if (!(_i5 < _Object$entries5.length)) {
605
+ _context4.next = 57;
606
+ break;
607
+ }
608
+ _Object$entries5$_i = _slicedToArray(_Object$entries5[_i5], 2), path = _Object$entries5$_i[0], content = _Object$entries5$_i[1];
609
+ if (!(path === "")) {
610
+ _context4.next = 53;
611
+ break;
612
+ }
613
+ _i6 = 0, _Object$entries6 = Object.entries(content);
614
+ case 12:
615
+ if (!(_i6 < _Object$entries6.length)) {
616
+ _context4.next = 51;
617
+ break;
618
+ }
619
+ _Object$entries6$_i = _slicedToArray(_Object$entries6[_i6], 2), _key = _Object$entries6$_i[0], _value = _Object$entries6$_i[1];
620
+ if (!isBytes(_value)) {
621
+ _context4.next = 25;
622
+ break;
623
+ }
624
+ length = _value.byteLength || _value.length || 0;
625
+ if (!(length === 0)) {
626
+ _context4.next = 21;
627
+ break;
628
+ }
629
+ // Empty binaries stay in headers
630
+ console.log("[encode] Empty binary field ".concat(_key, " staying in headers"));
631
+ return _context4.abrupt("continue", 48);
632
+ case 21:
633
+ console.log("[encode] Binary field ".concat(_key, " going to body"));
634
+ bodyKeys.push(_key);
635
+ case 23:
636
+ _context4.next = 48;
637
+ break;
638
+ case 25:
639
+ valueStr = String(_value);
640
+ type = types[_key];
641
+ if (!(type === "empty-binary" && valueStr === "")) {
642
+ _context4.next = 29;
643
+ break;
644
+ }
645
+ return _context4.abrupt("continue", 48);
646
+ case 29:
647
+ _context4.next = 31;
648
+ return hasNewline(valueStr);
649
+ case 31:
650
+ _context4.t3 = !_context4.sent;
651
+ if (!_context4.t3) {
652
+ _context4.next = 34;
653
+ break;
654
+ }
655
+ _context4.t3 = !_key.includes("/");
656
+ case 34:
657
+ _context4.t2 = _context4.t3;
658
+ if (!_context4.t2) {
659
+ _context4.next = 37;
660
+ break;
661
+ }
662
+ _context4.t2 = Buffer.from(valueStr).byteLength <= MAX_HEADER_LENGTH;
663
+ case 37:
664
+ _context4.t1 = _context4.t2;
665
+ if (!_context4.t1) {
666
+ _context4.next = 40;
667
+ break;
668
+ }
669
+ _context4.t1 = !isPojo(_value);
670
+ case 40:
671
+ _context4.t0 = _context4.t1;
672
+ if (!_context4.t0) {
673
+ _context4.next = 43;
674
+ break;
675
+ }
676
+ _context4.t0 = !(_key === "data" || _key === "body");
677
+ case 43:
678
+ if (!_context4.t0) {
679
+ _context4.next = 47;
680
+ break;
681
+ }
682
+ if (typeof _value === "number") {
683
+ headers[_key] = String(_value);
684
+ } else if (typeof _value === "boolean") {
685
+ headers[_key] = "\"".concat(_value, "\"");
686
+ } else if (_value === "[]" && type === "empty_list") {
687
+ headers[_key] = "[]";
688
+ } else if (_value === '"null"' || _value === '"undefined"') {
689
+ headers[_key] = _value;
690
+ } else {
691
+ headers[_key] = _value;
692
+ }
693
+ _context4.next = 48;
694
+ break;
695
+ case 47:
696
+ bodyKeys.push(_key);
697
+ case 48:
698
+ _i6++;
699
+ _context4.next = 12;
700
+ break;
701
+ case 51:
702
+ _context4.next = 54;
703
+ break;
704
+ case 53:
705
+ bodyKeys.push(path);
706
+ case 54:
707
+ _i5++;
708
+ _context4.next = 8;
709
+ break;
710
+ case 57:
711
+ console.log("[encode] Headers before filtering:", headers, "BodyKeys:", bodyKeys);
712
+ bodyKeys.sort();
713
+
714
+ // Add types for values in headers
715
+ for (_i7 = 0, _Object$entries7 = Object.entries(headers); _i7 < _Object$entries7.length; _i7++) {
716
+ _Object$entries7$_i = _slicedToArray(_Object$entries7[_i7], 2), _key2 = _Object$entries7$_i[0], _value2 = _Object$entries7$_i[1];
717
+ _type = types[_key2];
718
+ if (_type) {
719
+ headerTypes.push("".concat(_key2, "=\"").concat(_type, "\""));
720
+ }
721
+ }
722
+
723
+ // Add types for empty values not in headers
724
+ for (_i8 = 0, _Object$entries8 = Object.entries(types); _i8 < _Object$entries8.length; _i8++) {
725
+ _Object$entries8$_i = _slicedToArray(_Object$entries8[_i8], 2), _key3 = _Object$entries8$_i[0], _type2 = _Object$entries8$_i[1];
726
+ if (!_key3.includes("/") && _type2.startsWith("empty") && !headers[_key3]) {
727
+ headerTypes.push("".concat(_key3, "=\"").concat(_type2.replace("empty_", "empty-"), "\""));
728
+ }
729
+ }
730
+ if (headerTypes.length > 0) {
731
+ headers["ao-types"] = headerTypes.sort().join(", ");
732
+ }
733
+ if (!(bodyKeys.length > 0)) {
734
+ _context4.next = 185;
735
+ break;
736
+ }
737
+ headers["body-keys"] = encode_body_keys(bodyKeys);
738
+ if (bodyKeys.includes("data") || bodyKeys.includes("body")) {
739
+ inlineKey = bodyKeys.find(function (k) {
740
+ return k === "data" || k === "body";
741
+ });
742
+ headers["inline-body-key"] = inlineKey;
743
+ }
744
+
745
+ // Create multipart body parts
746
+ _iterator = _createForOfIteratorHelper(bodyKeys);
747
+ _context4.prev = 66;
748
+ _iterator.s();
749
+ case 68:
750
+ if ((_step = _iterator.n()).done) {
751
+ _context4.next = 133;
752
+ break;
753
+ }
754
+ _path = _step.value;
755
+ console.log("[encode] Processing bodyKey: ".concat(_path));
756
+
757
+ // Handle root-level fields
758
+ if (_path.includes("/")) {
759
+ _context4.next = 94;
760
+ break;
761
+ }
762
+ // This is a root-level field
763
+ fieldValue = parts[""] && parts[""][_path];
764
+ console.log("[encode] Root field ".concat(_path, " value:"), fieldValue);
765
+ if (!(fieldValue !== undefined)) {
766
+ _context4.next = 94;
767
+ break;
768
+ }
769
+ if (!isBytes(fieldValue)) {
770
+ _context4.next = 84;
771
+ break;
772
+ }
773
+ // Binary field - create a simple multipart section
774
+ // The format should be:
775
+ // content-disposition: form-data;name="fieldname"
776
+ // [empty line]
777
+ // [binary data]
778
+ headerStr = "content-disposition: form-data;name=\"".concat(_path, "\"\r\n\r\n");
779
+ headerBlob = new Blob([headerStr]);
780
+ dataBlob = new Blob([fieldValue]);
781
+ bodyParts.push(new Blob([headerBlob, dataBlob]));
782
+ console.log("[encode] Added binary field ".concat(_path, " to bodyParts"));
783
+ return _context4.abrupt("continue", 131);
784
+ case 84:
785
+ // Non-binary root field that needs to go in body
786
+ _lines = []; // Check if this is an inline key
787
+ _isInlineKey = _path === "data" || _path === "body";
788
+ if (_isInlineKey) {
789
+ _lines.push("content-disposition: inline");
790
+ } else {
791
+ _lines.push("content-disposition: form-data;name=\"".concat(_path, "\""));
792
+ }
793
+
794
+ // Add the field type if available
795
+ _type3 = types[_path];
796
+ if (_type3) {
797
+ _lines.push("ao-types: ".concat(_path, "=\"").concat(_type3, "\""));
798
+ }
799
+
800
+ // Add empty line before content
801
+ _lines.push("");
802
+
803
+ // Add the actual value
804
+ _lines.push(String(fieldValue));
805
+ bodyParts.push(new Blob([_lines.join("\r\n")]));
806
+ console.log("[encode] Added non-binary field ".concat(_path, " to bodyParts"));
807
+ return _context4.abrupt("continue", 131);
808
+ case 94:
809
+ // Handle nested paths
810
+ _content = parts[_path];
811
+ if (_content) {
812
+ _context4.next = 98;
813
+ break;
814
+ }
815
+ console.log("[encode] No content found for path: ".concat(_path));
816
+ return _context4.abrupt("continue", 131);
817
+ case 98:
818
+ lines = [];
819
+ binaryParts = [];
820
+ isInlineKey = (_path === "data" || _path === "body") && !_path.includes("/");
821
+ sortedKeys = Object.keys(_content).sort(); // Collect ao-types for this part
822
+ partTypes = [];
823
+ _iterator3 = _createForOfIteratorHelper(sortedKeys);
824
+ try {
825
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
826
+ _key4 = _step3.value;
827
+ fullPath = _path ? "".concat(_path, "/").concat(_key4) : _key4;
828
+ _type4 = types[fullPath];
829
+ if (_type4) {
830
+ partTypes.push("".concat(_key4, "=\"").concat(_type4, "\""));
831
+ }
832
+ }
833
+ } catch (err) {
834
+ _iterator3.e(err);
835
+ } finally {
836
+ _iterator3.f();
837
+ }
838
+ if (partTypes.length > 0) {
839
+ lines.push("ao-types: ".concat(partTypes.sort().join(", ")));
840
+ }
841
+ if (isInlineKey) {
842
+ lines.push("content-disposition: inline");
843
+ } else {
844
+ lines.push("content-disposition: form-data;name=\"".concat(_path, "\""));
845
+ }
846
+
847
+ // Add content fields
848
+ _iterator4 = _createForOfIteratorHelper(sortedKeys);
849
+ _context4.prev = 108;
850
+ _iterator4.s();
851
+ case 110:
852
+ if ((_step4 = _iterator4.n()).done) {
853
+ _context4.next = 122;
854
+ break;
855
+ }
856
+ _key5 = _step4.value;
857
+ _value3 = _content[_key5];
858
+ _fullPath = _path ? "".concat(_path, "/").concat(_key5) : _key5;
859
+ _type5 = types[_fullPath];
860
+ if (!(_type5 === "empty-message" || _type5 === "empty-list" || _type5 === "empty-binary")) {
861
+ _context4.next = 117;
862
+ break;
863
+ }
864
+ return _context4.abrupt("continue", 120);
865
+ case 117:
866
+ if (!((_value3 === "[]" || _value3 === "{}" || _value3 === "") && _type5 && _type5.startsWith("empty"))) {
867
+ _context4.next = 119;
868
+ break;
869
+ }
870
+ return _context4.abrupt("continue", 120);
871
+ case 119:
872
+ if (isBytes(_value3)) {
873
+ binaryParts.push({
874
+ key: _key5,
875
+ value: _value3
876
+ });
877
+ } else if (_type5 === "atom" && typeof _value3 === "boolean") {
878
+ lines.push("".concat(_key5, ": \"").concat(_value3, "\""));
879
+ } else if (_typeof(_value3) === "symbol") {
880
+ // Handle Symbol values
881
+ symbolValue = _value3.description || "symbol";
882
+ lines.push("".concat(_key5, ": ").concat(symbolValue));
883
+ } else {
884
+ lines.push("".concat(_key5, ": ").concat(_value3));
885
+ }
886
+ case 120:
887
+ _context4.next = 110;
888
+ break;
889
+ case 122:
890
+ _context4.next = 127;
891
+ break;
892
+ case 124:
893
+ _context4.prev = 124;
894
+ _context4.t4 = _context4["catch"](108);
895
+ _iterator4.e(_context4.t4);
896
+ case 127:
897
+ _context4.prev = 127;
898
+ _iterator4.f();
899
+ return _context4.finish(127);
900
+ case 130:
901
+ if (lines.length >= 1 || binaryParts.length > 0) {
902
+ if (binaryParts.length > 0) {
903
+ allParts = []; // Add text headers first
904
+ if (lines.length > 0) {
905
+ allParts.push(lines.join("\r\n"));
906
+ allParts.push("\r\n");
907
+ }
908
+
909
+ // Add binary data
910
+ _iterator5 = _createForOfIteratorHelper(binaryParts);
911
+ try {
912
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
913
+ binaryPart = _step5.value;
914
+ allParts.push("".concat(binaryPart.key, ": "));
915
+ allParts.push(binaryPart.value);
916
+ if (binaryParts.indexOf(binaryPart) < binaryParts.length - 1) {
917
+ allParts.push("\r\n");
918
+ }
919
+ }
920
+ } catch (err) {
921
+ _iterator5.e(err);
922
+ } finally {
923
+ _iterator5.f();
924
+ }
925
+ bodyParts.push(new Blob(allParts));
926
+ } else {
927
+ bodyParts.push(new Blob([lines.join("\r\n")]));
928
+ }
929
+ }
930
+ case 131:
931
+ _context4.next = 68;
932
+ break;
933
+ case 133:
934
+ _context4.next = 138;
935
+ break;
936
+ case 135:
937
+ _context4.prev = 135;
938
+ _context4.t5 = _context4["catch"](66);
939
+ _iterator.e(_context4.t5);
940
+ case 138:
941
+ _context4.prev = 138;
942
+ _iterator.f();
943
+ return _context4.finish(138);
944
+ case 141:
945
+ console.log("[encode] Total bodyParts: ".concat(bodyParts.length));
946
+
947
+ // Create boundary based on parts content
948
+ partsForBoundary = [];
949
+ _iterator2 = _createForOfIteratorHelper(bodyParts);
950
+ _context4.prev = 144;
951
+ _iterator2.s();
952
+ case 146:
953
+ if ((_step2 = _iterator2.n()).done) {
954
+ _context4.next = 154;
955
+ break;
956
+ }
957
+ part = _step2.value;
958
+ _context4.next = 150;
959
+ return part.text();
960
+ case 150:
961
+ partContent = _context4.sent;
962
+ partsForBoundary.push(partContent);
963
+ case 152:
964
+ _context4.next = 146;
965
+ break;
966
+ case 154:
967
+ _context4.next = 159;
968
+ break;
969
+ case 156:
970
+ _context4.prev = 156;
971
+ _context4.t6 = _context4["catch"](144);
972
+ _iterator2.e(_context4.t6);
973
+ case 159:
974
+ _context4.prev = 159;
975
+ _iterator2.f();
976
+ return _context4.finish(159);
977
+ case 162:
978
+ allPartsContent = partsForBoundary.join("");
979
+ console.log("[encode] All parts content length: ".concat(allPartsContent.length));
980
+ allPartsBuffer = Buffer.from(allPartsContent);
981
+ _context4.next = 167;
982
+ return sha256(allPartsBuffer.buffer.slice(allPartsBuffer.byteOffset, allPartsBuffer.byteOffset + allPartsBuffer.byteLength));
983
+ case 167:
984
+ hashResult = _context4.sent;
985
+ boundary = _base64url["default"].encode(Buffer.from(hashResult)); // Create final multipart body
986
+ finalParts = [];
987
+ for (i = 0; i < bodyParts.length; i++) {
988
+ finalParts.push("--".concat(boundary));
989
+ finalParts.push("\r\n");
990
+ finalParts.push(bodyParts[i]);
991
+ if (i < bodyParts.length - 1) {
992
+ finalParts.push("\r\n");
993
+ }
994
+ }
995
+ finalParts.push("\r\n--".concat(boundary, "--"));
996
+ headers["content-type"] = "multipart/form-data; boundary=\"".concat(boundary, "\"");
997
+ body = new Blob(finalParts);
998
+ _context4.next = 176;
999
+ return body.arrayBuffer();
1000
+ case 176:
1001
+ finalContent = _context4.sent;
1002
+ _context4.next = 179;
1003
+ return sha256(finalContent);
1004
+ case 179:
1005
+ contentDigest = _context4.sent;
1006
+ base64 = _base64url["default"].toBase64(_base64url["default"].encode(contentDigest));
1007
+ headers["content-digest"] = "sha-256=:".concat(base64, ":");
1008
+ headers["content-length"] = String(finalContent.byteLength);
1009
+ console.log("[encode] FINAL - headers:", headers, "body:", body);
1010
+ return _context4.abrupt("return", {
1011
+ headers: headers,
1012
+ body: body
1013
+ });
1014
+ case 185:
1015
+ console.log("[encode] FINAL - headers:", headers, "body:", undefined);
1016
+ return _context4.abrupt("return", {
1017
+ headers: headers,
1018
+ body: undefined
1019
+ });
1020
+ case 187:
1021
+ case "end":
1022
+ return _context4.stop();
1023
+ }
1024
+ }, _callee4, null, [[66, 135, 138, 141], [108, 124, 127, 130], [144, 156, 159, 162]]);
1025
+ }));
1026
+ return _encodeMultipart.apply(this, arguments);
1027
+ }
1028
+ function enc(_x4) {
1029
+ return _enc.apply(this, arguments);
1030
+ }
1031
+ function _enc() {
1032
+ _enc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(fields) {
1033
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1034
+ while (1) switch (_context5.prev = _context5.next) {
1035
+ case 0:
1036
+ _context5.next = 2;
1037
+ return encode(fields);
1038
+ case 2:
1039
+ return _context5.abrupt("return", _context5.sent);
1040
+ case 3:
1041
+ case "end":
1042
+ return _context5.stop();
1043
+ }
1044
+ }, _callee5);
1045
+ }));
1046
+ return _enc.apply(this, arguments);
1047
+ }