@balancy/wasm 1.0.39 → 1.0.40
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/dist/Balancy.wasm +0 -0
- package/dist/index.cjs.js +149 -31
- package/dist/index.es.js +149 -31
- package/dist/index.umd.js +149 -31
- package/dist/node/index.cjs.js +149 -31
- package/dist/node/index.es.js +149 -31
- package/dist/node/index.umd.js +149 -31
- package/package.json +1 -1
package/dist/Balancy.wasm
CHANGED
|
Binary file
|
package/dist/index.cjs.js
CHANGED
|
@@ -1195,17 +1195,18 @@ var Balancy = function() {
|
|
|
1195
1195
|
});
|
|
1196
1196
|
}
|
|
1197
1197
|
}
|
|
1198
|
-
function js_fetch(url, bLoadFile, method, headers, headersCount, body, successCallbackPtr, errorCallbackPtr, callbackPtr, binaryCallbackPtr) {
|
|
1198
|
+
function js_fetch(url, bLoadFile, method, headers, headersCount, body, successCallbackPtr, errorCallbackPtr, callbackPtr, binaryCallbackPtr, requestContextPtr) {
|
|
1199
|
+
var requestId = Date.now() + Math.random();
|
|
1199
1200
|
var urlString = "";
|
|
1200
1201
|
var methodString = "";
|
|
1201
1202
|
var bodyString = null;
|
|
1202
1203
|
try {
|
|
1203
1204
|
if (!url) {
|
|
1204
|
-
console.error("
|
|
1205
|
+
console.error("[ERROR] [Request ".concat(requestId, "] URL pointer is null"));
|
|
1205
1206
|
return;
|
|
1206
1207
|
}
|
|
1207
1208
|
if (!method) {
|
|
1208
|
-
console.error("
|
|
1209
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Method pointer is null"));
|
|
1209
1210
|
return;
|
|
1210
1211
|
}
|
|
1211
1212
|
urlString = UTF8ToString(url);
|
|
@@ -1214,51 +1215,92 @@ var Balancy = function() {
|
|
|
1214
1215
|
bodyString = UTF8ToString(body);
|
|
1215
1216
|
}
|
|
1216
1217
|
if (!urlString || urlString.length === 0) {
|
|
1217
|
-
console.error("
|
|
1218
|
+
console.error("[ERROR] [Request ".concat(requestId, "] URL is empty or invalid"));
|
|
1218
1219
|
return;
|
|
1219
1220
|
}
|
|
1220
1221
|
if (urlString.includes("\0") || urlString.includes("")) {
|
|
1221
|
-
console.error("
|
|
1222
|
+
console.error("[ERROR] [Request ".concat(requestId, "] URL contains invalid characters:"), urlString);
|
|
1222
1223
|
return;
|
|
1223
1224
|
}
|
|
1225
|
+
console.log("[START] [Request ".concat(requestId, "] Starting ").concat(bLoadFile ? "FILE LOAD" : "API REQUEST"));
|
|
1226
|
+
console.log(" URL: ".concat(urlString));
|
|
1227
|
+
console.log(" Method: ".concat(methodString));
|
|
1228
|
+
if (bodyString) {
|
|
1229
|
+
console.log(" Body: ".concat(bodyString.length > 200 ? bodyString.substring(0, 200) + "..." : bodyString));
|
|
1230
|
+
}
|
|
1224
1231
|
} catch (error) {
|
|
1225
|
-
console.error("
|
|
1232
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error reading strings from WASM memory:"), error);
|
|
1226
1233
|
return;
|
|
1227
1234
|
}
|
|
1228
|
-
var invokeErrorCallback = function(status, message
|
|
1229
|
-
|
|
1235
|
+
var invokeErrorCallback = function(status, message) {
|
|
1236
|
+
var details = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "";
|
|
1237
|
+
var fullMessage = "[Request ".concat(requestId, "] ").concat(bLoadFile ? "FILE LOAD" : "API REQUEST", " FAILED: ").concat(methodString, " ").concat(urlString).concat(details ? " - " + details : "");
|
|
1238
|
+
console.error("[ERROR] ".concat(fullMessage));
|
|
1239
|
+
console.error(" Status: ".concat(status));
|
|
1240
|
+
console.error(" Error: ".concat(message || "Unknown error"));
|
|
1241
|
+
if (bodyString) {
|
|
1242
|
+
console.error(" Request Body: ".concat(bodyString.length > 500 ? bodyString.substring(0, 500) + "..." : bodyString));
|
|
1243
|
+
}
|
|
1230
1244
|
try {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1245
|
+
if (requestContextPtr) {
|
|
1246
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Cleaning up RequestContext at ").concat(requestContextPtr));
|
|
1247
|
+
Module._free(requestContextPtr);
|
|
1248
|
+
}
|
|
1249
|
+
if (!errorCallbackPtr || !callbackPtr) {
|
|
1250
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid callback pointers: errorCallback=").concat(errorCallbackPtr, ", callback=").concat(callbackPtr));
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
var errorMessage = fullMessage + (message ? " - ".concat(message) : "");
|
|
1254
|
+
var errorLength = lengthBytesUTF8(errorMessage);
|
|
1255
|
+
if (errorLength <= 0 || errorLength > 1048576) {
|
|
1256
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid error message length: ").concat(errorLength));
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
var errorPtr = Module._malloc(errorLength + 1);
|
|
1260
|
+
if (!errorPtr) {
|
|
1261
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Failed to allocate memory for error message"));
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Allocated ").concat(errorLength + 1, " bytes for error message at ").concat(errorPtr));
|
|
1265
|
+
stringToUTF8(errorMessage, errorPtr, errorLength + 1);
|
|
1266
|
+
if (typeof Module["dynCall_viii"] !== "function") {
|
|
1267
|
+
console.error("[ERROR] [Request ".concat(requestId, "] dynCall_viii function not available"));
|
|
1268
|
+
Module._free(errorPtr);
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1235
1271
|
Module["dynCall_viii"](errorCallbackPtr, status, errorPtr, callbackPtr);
|
|
1236
1272
|
Module._free(errorPtr);
|
|
1273
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Freed error message memory at ").concat(errorPtr));
|
|
1237
1274
|
} catch (error) {
|
|
1238
|
-
console.error("
|
|
1275
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error in error callback:"), error);
|
|
1239
1276
|
}
|
|
1240
1277
|
};
|
|
1241
1278
|
var headersObj = new Headers;
|
|
1242
1279
|
var ptrSize = Module.HEAPU32.BYTES_PER_ELEMENT;
|
|
1280
|
+
var headersLogged = [];
|
|
1243
1281
|
try {
|
|
1244
1282
|
for(var i = 0; i < headersCount; i += 2){
|
|
1245
1283
|
var keyPtr = getValue(headers + i * ptrSize, "*");
|
|
1246
1284
|
var valuePtr = getValue(headers + (i + 1) * ptrSize, "*");
|
|
1247
1285
|
if (!keyPtr || !valuePtr) {
|
|
1248
|
-
console.warn("
|
|
1286
|
+
console.warn("[WARN] [Request ".concat(requestId, "] Skipping invalid header pointer at index"), i);
|
|
1249
1287
|
continue;
|
|
1250
1288
|
}
|
|
1251
1289
|
var key = UTF8ToString(keyPtr);
|
|
1252
1290
|
var value = UTF8ToString(valuePtr);
|
|
1253
1291
|
if (!key || !value) {
|
|
1254
|
-
console.warn("
|
|
1292
|
+
console.warn("[WARN] [Request ".concat(requestId, "] Skipping empty header at index"), i);
|
|
1255
1293
|
continue;
|
|
1256
1294
|
}
|
|
1257
1295
|
headersObj.append(key, value);
|
|
1296
|
+
headersLogged.push("".concat(key, ": ").concat(value));
|
|
1297
|
+
}
|
|
1298
|
+
if (headersLogged.length > 0) {
|
|
1299
|
+
console.log(" Headers: ".concat(headersLogged.join(", ")));
|
|
1258
1300
|
}
|
|
1259
1301
|
} catch (error) {
|
|
1260
|
-
console.error("
|
|
1261
|
-
invokeErrorCallback(-1, "Header processing error: " + error.message,
|
|
1302
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error processing headers:"), error);
|
|
1303
|
+
invokeErrorCallback(-1, "Header processing error: " + error.message, "");
|
|
1262
1304
|
return;
|
|
1263
1305
|
}
|
|
1264
1306
|
var fetchOptions = {
|
|
@@ -1266,19 +1308,24 @@ var Balancy = function() {
|
|
|
1266
1308
|
headers: headersObj,
|
|
1267
1309
|
body: bodyString
|
|
1268
1310
|
};
|
|
1311
|
+
var startTime = performance.now();
|
|
1269
1312
|
fetch(urlString, fetchOptions).then(function(response) {
|
|
1313
|
+
var duration = performance.now() - startTime;
|
|
1314
|
+
console.log("[TIMING] [Request ".concat(requestId, "] Fetch completed in ").concat(duration.toFixed(2), "ms"));
|
|
1270
1315
|
if (!response.ok) {
|
|
1271
|
-
console.
|
|
1316
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Response not OK, status: ").concat(response.status, " ").concat(response.statusText));
|
|
1272
1317
|
response.text().then(function(errorMessage) {
|
|
1273
|
-
console.
|
|
1274
|
-
invokeErrorCallback(response.status, errorMessage,
|
|
1318
|
+
console.error(" Response Body: ".concat(errorMessage));
|
|
1319
|
+
invokeErrorCallback(response.status, errorMessage, "HTTP ".concat(response.status, " ").concat(response.statusText));
|
|
1275
1320
|
}).catch(function() {
|
|
1276
|
-
console.
|
|
1277
|
-
invokeErrorCallback(response.status,
|
|
1321
|
+
console.error(" Failed to read error response body");
|
|
1322
|
+
invokeErrorCallback(response.status, "HTTP ".concat(response.status, " ").concat(response.statusText), "Could not read response body");
|
|
1278
1323
|
});
|
|
1279
1324
|
return;
|
|
1280
1325
|
}
|
|
1326
|
+
console.log("[SUCCESS] [Request ".concat(requestId, "] Response OK, status: ").concat(response.status));
|
|
1281
1327
|
var contentType = response.headers.get("content-type") || "";
|
|
1328
|
+
console.log(" Content-Type: ".concat(contentType));
|
|
1282
1329
|
var binaryExtensions = [
|
|
1283
1330
|
".png",
|
|
1284
1331
|
".jpg",
|
|
@@ -1319,33 +1366,104 @@ var Balancy = function() {
|
|
|
1319
1366
|
return contentType.toLowerCase().includes(type);
|
|
1320
1367
|
});
|
|
1321
1368
|
var isBinary = contentType.includes("application/octet-stream") || hasBinaryExtension || !isTextMimeType && !contentType.includes("charset");
|
|
1369
|
+
console.log(" Detected as: ".concat(isBinary ? "BINARY" : "TEXT", " data"));
|
|
1322
1370
|
if (isBinary) {
|
|
1323
1371
|
response.arrayBuffer().then(function(arrayBuffer) {
|
|
1324
1372
|
var dataSize = arrayBuffer.byteLength;
|
|
1373
|
+
console.log("[DATA] [Request ".concat(requestId, "] Binary data received: ").concat(dataSize, " bytes"));
|
|
1374
|
+
if (dataSize <= 0 || dataSize > 104857600) {
|
|
1375
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid binary data size: ").concat(dataSize));
|
|
1376
|
+
invokeErrorCallback(-1, "Invalid binary data size: ".concat(dataSize), "");
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1325
1379
|
var dataPtr = Module._malloc(dataSize);
|
|
1380
|
+
if (!dataPtr) {
|
|
1381
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Failed to allocate ").concat(dataSize, " bytes for binary data"));
|
|
1382
|
+
invokeErrorCallback(-1, "Memory allocation failed for binary data", "");
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Allocated ").concat(dataSize, " bytes for binary data at ").concat(dataPtr));
|
|
1326
1386
|
var dataView = new Uint8Array(arrayBuffer);
|
|
1327
1387
|
Module.HEAPU8.set(dataView, dataPtr);
|
|
1328
|
-
|
|
1388
|
+
try {
|
|
1389
|
+
if (!binaryCallbackPtr || !callbackPtr) {
|
|
1390
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid binary callback pointers: binary=").concat(binaryCallbackPtr, ", callback=").concat(callbackPtr));
|
|
1391
|
+
Module._free(dataPtr);
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
if (typeof Module["dynCall_viii"] !== "function") {
|
|
1395
|
+
console.error("[ERROR] [Request ".concat(requestId, "] dynCall_viii function not available for binary callback"));
|
|
1396
|
+
Module._free(dataPtr);
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
Module["dynCall_viii"](binaryCallbackPtr, dataPtr, dataSize, callbackPtr);
|
|
1400
|
+
console.log("[SUCCESS] [Request ".concat(requestId, "] Binary callback completed successfully"));
|
|
1401
|
+
if (requestContextPtr) {
|
|
1402
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Cleaning up RequestContext at ").concat(requestContextPtr));
|
|
1403
|
+
Module._free(requestContextPtr);
|
|
1404
|
+
}
|
|
1405
|
+
} catch (error) {
|
|
1406
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error calling binary callback:"), error);
|
|
1407
|
+
invokeErrorCallback(-1, "Binary callback error: " + error.message, "");
|
|
1408
|
+
}
|
|
1329
1409
|
Module._free(dataPtr);
|
|
1410
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Freed binary data memory at ").concat(dataPtr));
|
|
1330
1411
|
}).catch(function(error) {
|
|
1331
|
-
console.
|
|
1332
|
-
invokeErrorCallback(-1, error.message,
|
|
1412
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error reading binary data:"), error);
|
|
1413
|
+
invokeErrorCallback(-1, error.message, "Failed to read binary response");
|
|
1333
1414
|
});
|
|
1334
1415
|
} else {
|
|
1335
1416
|
response.text().then(function(data) {
|
|
1336
1417
|
var dataLength = lengthBytesUTF8(data);
|
|
1418
|
+
console.log("[DATA] [Request ".concat(requestId, "] Text data received: ").concat(dataLength, " bytes"));
|
|
1419
|
+
if (data.length > 0) {
|
|
1420
|
+
console.log(" Preview: ".concat(data.substring(0, 200)).concat(data.length > 200 ? "..." : ""));
|
|
1421
|
+
}
|
|
1422
|
+
if (dataLength <= 0 || dataLength > 104857600) {
|
|
1423
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid text data size: ").concat(dataLength));
|
|
1424
|
+
invokeErrorCallback(-1, "Invalid text data size: ".concat(dataLength), "");
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1337
1427
|
var dataPtr = Module._malloc(dataLength + 1);
|
|
1338
|
-
|
|
1339
|
-
|
|
1428
|
+
if (!dataPtr) {
|
|
1429
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Failed to allocate ").concat(dataLength + 1, " bytes for text data"));
|
|
1430
|
+
invokeErrorCallback(-1, "Memory allocation failed for text data", "");
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Allocated ").concat(dataLength + 1, " bytes for text data at ").concat(dataPtr));
|
|
1434
|
+
try {
|
|
1435
|
+
stringToUTF8(data, dataPtr, dataLength + 1);
|
|
1436
|
+
if (!successCallbackPtr || !callbackPtr) {
|
|
1437
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid text callback pointers: success=").concat(successCallbackPtr, ", callback=").concat(callbackPtr));
|
|
1438
|
+
Module._free(dataPtr);
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
if (typeof Module["dynCall_viii"] !== "function") {
|
|
1442
|
+
console.error("[ERROR] [Request ".concat(requestId, "] dynCall_viii function not available for text callback"));
|
|
1443
|
+
Module._free(dataPtr);
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
Module["dynCall_viii"](successCallbackPtr, dataPtr, dataLength, callbackPtr);
|
|
1447
|
+
console.log("[SUCCESS] [Request ".concat(requestId, "] Text callback completed successfully"));
|
|
1448
|
+
if (requestContextPtr) {
|
|
1449
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Cleaning up RequestContext at ").concat(requestContextPtr));
|
|
1450
|
+
Module._free(requestContextPtr);
|
|
1451
|
+
}
|
|
1452
|
+
} catch (error) {
|
|
1453
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error calling text callback:"), error);
|
|
1454
|
+
invokeErrorCallback(-1, "Text callback error: " + error.message, "");
|
|
1455
|
+
}
|
|
1340
1456
|
Module._free(dataPtr);
|
|
1457
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Freed text data memory at ").concat(dataPtr));
|
|
1341
1458
|
}).catch(function(error) {
|
|
1342
|
-
console.
|
|
1343
|
-
invokeErrorCallback(-1, error.message,
|
|
1459
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error reading text data:"), error);
|
|
1460
|
+
invokeErrorCallback(-1, error.message, "Failed to read text response");
|
|
1344
1461
|
});
|
|
1345
1462
|
}
|
|
1346
1463
|
}).catch(function(error) {
|
|
1347
|
-
|
|
1348
|
-
|
|
1464
|
+
var duration = performance.now() - startTime;
|
|
1465
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Fetch error after ").concat(duration.toFixed(2), "ms:"), error);
|
|
1466
|
+
invokeErrorCallback(-1, error.message, "Network fetch failed");
|
|
1349
1467
|
});
|
|
1350
1468
|
}
|
|
1351
1469
|
function js_call_typescript_bridge_send_ack(connectionId, ackId, responseData) {
|
package/dist/index.es.js
CHANGED
|
@@ -1190,17 +1190,18 @@ var Balancy = function() {
|
|
|
1190
1190
|
});
|
|
1191
1191
|
}
|
|
1192
1192
|
}
|
|
1193
|
-
function js_fetch(url, bLoadFile, method, headers, headersCount, body, successCallbackPtr, errorCallbackPtr, callbackPtr, binaryCallbackPtr) {
|
|
1193
|
+
function js_fetch(url, bLoadFile, method, headers, headersCount, body, successCallbackPtr, errorCallbackPtr, callbackPtr, binaryCallbackPtr, requestContextPtr) {
|
|
1194
|
+
var requestId = Date.now() + Math.random();
|
|
1194
1195
|
var urlString = "";
|
|
1195
1196
|
var methodString = "";
|
|
1196
1197
|
var bodyString = null;
|
|
1197
1198
|
try {
|
|
1198
1199
|
if (!url) {
|
|
1199
|
-
console.error("
|
|
1200
|
+
console.error("[ERROR] [Request ".concat(requestId, "] URL pointer is null"));
|
|
1200
1201
|
return;
|
|
1201
1202
|
}
|
|
1202
1203
|
if (!method) {
|
|
1203
|
-
console.error("
|
|
1204
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Method pointer is null"));
|
|
1204
1205
|
return;
|
|
1205
1206
|
}
|
|
1206
1207
|
urlString = UTF8ToString(url);
|
|
@@ -1209,51 +1210,92 @@ var Balancy = function() {
|
|
|
1209
1210
|
bodyString = UTF8ToString(body);
|
|
1210
1211
|
}
|
|
1211
1212
|
if (!urlString || urlString.length === 0) {
|
|
1212
|
-
console.error("
|
|
1213
|
+
console.error("[ERROR] [Request ".concat(requestId, "] URL is empty or invalid"));
|
|
1213
1214
|
return;
|
|
1214
1215
|
}
|
|
1215
1216
|
if (urlString.includes("\0") || urlString.includes("")) {
|
|
1216
|
-
console.error("
|
|
1217
|
+
console.error("[ERROR] [Request ".concat(requestId, "] URL contains invalid characters:"), urlString);
|
|
1217
1218
|
return;
|
|
1218
1219
|
}
|
|
1220
|
+
console.log("[START] [Request ".concat(requestId, "] Starting ").concat(bLoadFile ? "FILE LOAD" : "API REQUEST"));
|
|
1221
|
+
console.log(" URL: ".concat(urlString));
|
|
1222
|
+
console.log(" Method: ".concat(methodString));
|
|
1223
|
+
if (bodyString) {
|
|
1224
|
+
console.log(" Body: ".concat(bodyString.length > 200 ? bodyString.substring(0, 200) + "..." : bodyString));
|
|
1225
|
+
}
|
|
1219
1226
|
} catch (error) {
|
|
1220
|
-
console.error("
|
|
1227
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error reading strings from WASM memory:"), error);
|
|
1221
1228
|
return;
|
|
1222
1229
|
}
|
|
1223
|
-
var invokeErrorCallback = function(status, message
|
|
1224
|
-
|
|
1230
|
+
var invokeErrorCallback = function(status, message) {
|
|
1231
|
+
var details = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "";
|
|
1232
|
+
var fullMessage = "[Request ".concat(requestId, "] ").concat(bLoadFile ? "FILE LOAD" : "API REQUEST", " FAILED: ").concat(methodString, " ").concat(urlString).concat(details ? " - " + details : "");
|
|
1233
|
+
console.error("[ERROR] ".concat(fullMessage));
|
|
1234
|
+
console.error(" Status: ".concat(status));
|
|
1235
|
+
console.error(" Error: ".concat(message || "Unknown error"));
|
|
1236
|
+
if (bodyString) {
|
|
1237
|
+
console.error(" Request Body: ".concat(bodyString.length > 500 ? bodyString.substring(0, 500) + "..." : bodyString));
|
|
1238
|
+
}
|
|
1225
1239
|
try {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1240
|
+
if (requestContextPtr) {
|
|
1241
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Cleaning up RequestContext at ").concat(requestContextPtr));
|
|
1242
|
+
Module._free(requestContextPtr);
|
|
1243
|
+
}
|
|
1244
|
+
if (!errorCallbackPtr || !callbackPtr) {
|
|
1245
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid callback pointers: errorCallback=").concat(errorCallbackPtr, ", callback=").concat(callbackPtr));
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
var errorMessage = fullMessage + (message ? " - ".concat(message) : "");
|
|
1249
|
+
var errorLength = lengthBytesUTF8(errorMessage);
|
|
1250
|
+
if (errorLength <= 0 || errorLength > 1048576) {
|
|
1251
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid error message length: ").concat(errorLength));
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
var errorPtr = Module._malloc(errorLength + 1);
|
|
1255
|
+
if (!errorPtr) {
|
|
1256
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Failed to allocate memory for error message"));
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Allocated ").concat(errorLength + 1, " bytes for error message at ").concat(errorPtr));
|
|
1260
|
+
stringToUTF8(errorMessage, errorPtr, errorLength + 1);
|
|
1261
|
+
if (typeof Module["dynCall_viii"] !== "function") {
|
|
1262
|
+
console.error("[ERROR] [Request ".concat(requestId, "] dynCall_viii function not available"));
|
|
1263
|
+
Module._free(errorPtr);
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1230
1266
|
Module["dynCall_viii"](errorCallbackPtr, status, errorPtr, callbackPtr);
|
|
1231
1267
|
Module._free(errorPtr);
|
|
1268
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Freed error message memory at ").concat(errorPtr));
|
|
1232
1269
|
} catch (error) {
|
|
1233
|
-
console.error("
|
|
1270
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error in error callback:"), error);
|
|
1234
1271
|
}
|
|
1235
1272
|
};
|
|
1236
1273
|
var headersObj = new Headers;
|
|
1237
1274
|
var ptrSize = Module.HEAPU32.BYTES_PER_ELEMENT;
|
|
1275
|
+
var headersLogged = [];
|
|
1238
1276
|
try {
|
|
1239
1277
|
for(var i = 0; i < headersCount; i += 2){
|
|
1240
1278
|
var keyPtr = getValue(headers + i * ptrSize, "*");
|
|
1241
1279
|
var valuePtr = getValue(headers + (i + 1) * ptrSize, "*");
|
|
1242
1280
|
if (!keyPtr || !valuePtr) {
|
|
1243
|
-
console.warn("
|
|
1281
|
+
console.warn("[WARN] [Request ".concat(requestId, "] Skipping invalid header pointer at index"), i);
|
|
1244
1282
|
continue;
|
|
1245
1283
|
}
|
|
1246
1284
|
var key = UTF8ToString(keyPtr);
|
|
1247
1285
|
var value = UTF8ToString(valuePtr);
|
|
1248
1286
|
if (!key || !value) {
|
|
1249
|
-
console.warn("
|
|
1287
|
+
console.warn("[WARN] [Request ".concat(requestId, "] Skipping empty header at index"), i);
|
|
1250
1288
|
continue;
|
|
1251
1289
|
}
|
|
1252
1290
|
headersObj.append(key, value);
|
|
1291
|
+
headersLogged.push("".concat(key, ": ").concat(value));
|
|
1292
|
+
}
|
|
1293
|
+
if (headersLogged.length > 0) {
|
|
1294
|
+
console.log(" Headers: ".concat(headersLogged.join(", ")));
|
|
1253
1295
|
}
|
|
1254
1296
|
} catch (error) {
|
|
1255
|
-
console.error("
|
|
1256
|
-
invokeErrorCallback(-1, "Header processing error: " + error.message,
|
|
1297
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error processing headers:"), error);
|
|
1298
|
+
invokeErrorCallback(-1, "Header processing error: " + error.message, "");
|
|
1257
1299
|
return;
|
|
1258
1300
|
}
|
|
1259
1301
|
var fetchOptions = {
|
|
@@ -1261,19 +1303,24 @@ var Balancy = function() {
|
|
|
1261
1303
|
headers: headersObj,
|
|
1262
1304
|
body: bodyString
|
|
1263
1305
|
};
|
|
1306
|
+
var startTime = performance.now();
|
|
1264
1307
|
fetch(urlString, fetchOptions).then(function(response) {
|
|
1308
|
+
var duration = performance.now() - startTime;
|
|
1309
|
+
console.log("[TIMING] [Request ".concat(requestId, "] Fetch completed in ").concat(duration.toFixed(2), "ms"));
|
|
1265
1310
|
if (!response.ok) {
|
|
1266
|
-
console.
|
|
1311
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Response not OK, status: ").concat(response.status, " ").concat(response.statusText));
|
|
1267
1312
|
response.text().then(function(errorMessage) {
|
|
1268
|
-
console.
|
|
1269
|
-
invokeErrorCallback(response.status, errorMessage,
|
|
1313
|
+
console.error(" Response Body: ".concat(errorMessage));
|
|
1314
|
+
invokeErrorCallback(response.status, errorMessage, "HTTP ".concat(response.status, " ").concat(response.statusText));
|
|
1270
1315
|
}).catch(function() {
|
|
1271
|
-
console.
|
|
1272
|
-
invokeErrorCallback(response.status,
|
|
1316
|
+
console.error(" Failed to read error response body");
|
|
1317
|
+
invokeErrorCallback(response.status, "HTTP ".concat(response.status, " ").concat(response.statusText), "Could not read response body");
|
|
1273
1318
|
});
|
|
1274
1319
|
return;
|
|
1275
1320
|
}
|
|
1321
|
+
console.log("[SUCCESS] [Request ".concat(requestId, "] Response OK, status: ").concat(response.status));
|
|
1276
1322
|
var contentType = response.headers.get("content-type") || "";
|
|
1323
|
+
console.log(" Content-Type: ".concat(contentType));
|
|
1277
1324
|
var binaryExtensions = [
|
|
1278
1325
|
".png",
|
|
1279
1326
|
".jpg",
|
|
@@ -1314,33 +1361,104 @@ var Balancy = function() {
|
|
|
1314
1361
|
return contentType.toLowerCase().includes(type);
|
|
1315
1362
|
});
|
|
1316
1363
|
var isBinary = contentType.includes("application/octet-stream") || hasBinaryExtension || !isTextMimeType && !contentType.includes("charset");
|
|
1364
|
+
console.log(" Detected as: ".concat(isBinary ? "BINARY" : "TEXT", " data"));
|
|
1317
1365
|
if (isBinary) {
|
|
1318
1366
|
response.arrayBuffer().then(function(arrayBuffer) {
|
|
1319
1367
|
var dataSize = arrayBuffer.byteLength;
|
|
1368
|
+
console.log("[DATA] [Request ".concat(requestId, "] Binary data received: ").concat(dataSize, " bytes"));
|
|
1369
|
+
if (dataSize <= 0 || dataSize > 104857600) {
|
|
1370
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid binary data size: ").concat(dataSize));
|
|
1371
|
+
invokeErrorCallback(-1, "Invalid binary data size: ".concat(dataSize), "");
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1320
1374
|
var dataPtr = Module._malloc(dataSize);
|
|
1375
|
+
if (!dataPtr) {
|
|
1376
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Failed to allocate ").concat(dataSize, " bytes for binary data"));
|
|
1377
|
+
invokeErrorCallback(-1, "Memory allocation failed for binary data", "");
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Allocated ").concat(dataSize, " bytes for binary data at ").concat(dataPtr));
|
|
1321
1381
|
var dataView = new Uint8Array(arrayBuffer);
|
|
1322
1382
|
Module.HEAPU8.set(dataView, dataPtr);
|
|
1323
|
-
|
|
1383
|
+
try {
|
|
1384
|
+
if (!binaryCallbackPtr || !callbackPtr) {
|
|
1385
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid binary callback pointers: binary=").concat(binaryCallbackPtr, ", callback=").concat(callbackPtr));
|
|
1386
|
+
Module._free(dataPtr);
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1389
|
+
if (typeof Module["dynCall_viii"] !== "function") {
|
|
1390
|
+
console.error("[ERROR] [Request ".concat(requestId, "] dynCall_viii function not available for binary callback"));
|
|
1391
|
+
Module._free(dataPtr);
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
Module["dynCall_viii"](binaryCallbackPtr, dataPtr, dataSize, callbackPtr);
|
|
1395
|
+
console.log("[SUCCESS] [Request ".concat(requestId, "] Binary callback completed successfully"));
|
|
1396
|
+
if (requestContextPtr) {
|
|
1397
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Cleaning up RequestContext at ").concat(requestContextPtr));
|
|
1398
|
+
Module._free(requestContextPtr);
|
|
1399
|
+
}
|
|
1400
|
+
} catch (error) {
|
|
1401
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error calling binary callback:"), error);
|
|
1402
|
+
invokeErrorCallback(-1, "Binary callback error: " + error.message, "");
|
|
1403
|
+
}
|
|
1324
1404
|
Module._free(dataPtr);
|
|
1405
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Freed binary data memory at ").concat(dataPtr));
|
|
1325
1406
|
}).catch(function(error) {
|
|
1326
|
-
console.
|
|
1327
|
-
invokeErrorCallback(-1, error.message,
|
|
1407
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error reading binary data:"), error);
|
|
1408
|
+
invokeErrorCallback(-1, error.message, "Failed to read binary response");
|
|
1328
1409
|
});
|
|
1329
1410
|
} else {
|
|
1330
1411
|
response.text().then(function(data) {
|
|
1331
1412
|
var dataLength = lengthBytesUTF8(data);
|
|
1413
|
+
console.log("[DATA] [Request ".concat(requestId, "] Text data received: ").concat(dataLength, " bytes"));
|
|
1414
|
+
if (data.length > 0) {
|
|
1415
|
+
console.log(" Preview: ".concat(data.substring(0, 200)).concat(data.length > 200 ? "..." : ""));
|
|
1416
|
+
}
|
|
1417
|
+
if (dataLength <= 0 || dataLength > 104857600) {
|
|
1418
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid text data size: ").concat(dataLength));
|
|
1419
|
+
invokeErrorCallback(-1, "Invalid text data size: ".concat(dataLength), "");
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1332
1422
|
var dataPtr = Module._malloc(dataLength + 1);
|
|
1333
|
-
|
|
1334
|
-
|
|
1423
|
+
if (!dataPtr) {
|
|
1424
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Failed to allocate ").concat(dataLength + 1, " bytes for text data"));
|
|
1425
|
+
invokeErrorCallback(-1, "Memory allocation failed for text data", "");
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1428
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Allocated ").concat(dataLength + 1, " bytes for text data at ").concat(dataPtr));
|
|
1429
|
+
try {
|
|
1430
|
+
stringToUTF8(data, dataPtr, dataLength + 1);
|
|
1431
|
+
if (!successCallbackPtr || !callbackPtr) {
|
|
1432
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Invalid text callback pointers: success=").concat(successCallbackPtr, ", callback=").concat(callbackPtr));
|
|
1433
|
+
Module._free(dataPtr);
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
if (typeof Module["dynCall_viii"] !== "function") {
|
|
1437
|
+
console.error("[ERROR] [Request ".concat(requestId, "] dynCall_viii function not available for text callback"));
|
|
1438
|
+
Module._free(dataPtr);
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
Module["dynCall_viii"](successCallbackPtr, dataPtr, dataLength, callbackPtr);
|
|
1442
|
+
console.log("[SUCCESS] [Request ".concat(requestId, "] Text callback completed successfully"));
|
|
1443
|
+
if (requestContextPtr) {
|
|
1444
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Cleaning up RequestContext at ").concat(requestContextPtr));
|
|
1445
|
+
Module._free(requestContextPtr);
|
|
1446
|
+
}
|
|
1447
|
+
} catch (error) {
|
|
1448
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error calling text callback:"), error);
|
|
1449
|
+
invokeErrorCallback(-1, "Text callback error: " + error.message, "");
|
|
1450
|
+
}
|
|
1335
1451
|
Module._free(dataPtr);
|
|
1452
|
+
console.log("[MEMORY] [Request ".concat(requestId, "] Freed text data memory at ").concat(dataPtr));
|
|
1336
1453
|
}).catch(function(error) {
|
|
1337
|
-
console.
|
|
1338
|
-
invokeErrorCallback(-1, error.message,
|
|
1454
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Error reading text data:"), error);
|
|
1455
|
+
invokeErrorCallback(-1, error.message, "Failed to read text response");
|
|
1339
1456
|
});
|
|
1340
1457
|
}
|
|
1341
1458
|
}).catch(function(error) {
|
|
1342
|
-
|
|
1343
|
-
|
|
1459
|
+
var duration = performance.now() - startTime;
|
|
1460
|
+
console.error("[ERROR] [Request ".concat(requestId, "] Fetch error after ").concat(duration.toFixed(2), "ms:"), error);
|
|
1461
|
+
invokeErrorCallback(-1, error.message, "Network fetch failed");
|
|
1344
1462
|
});
|
|
1345
1463
|
}
|
|
1346
1464
|
function js_call_typescript_bridge_send_ack(connectionId, ackId, responseData) {
|