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