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