remove redundand test files

This commit is contained in:
2026-03-09 10:53:12 +07:00
parent cf59b4c8fb
commit e697ab060c
24 changed files with 318 additions and 4069 deletions

View File

@@ -6,6 +6,8 @@
* using NATS as the message bus, with support for both direct payload transport and
* URL-based transport for larger payloads.
*
* Supported payload types: "text", "dictionary", "arrowtable", "jsontable", "image", "audio", "video", "binary"
*
* @module NATSBridge
*/
@@ -57,7 +59,7 @@ function logTrace(correlationId, message) {
/**
* Serialize data according to specified format
* @param {any} data - Data to serialize
* @param {string} payloadType - Target format: "text", "dictionary", "table", "image", "audio", "video", "binary"
* @param {string} payloadType - Target format: "text", "dictionary", "arrowtable", "jsontable", "image", "audio", "video", "binary"
* @returns {Buffer} Binary representation of the serialized data
*/
async function serializeData(data, payloadType) {
@@ -70,13 +72,20 @@ async function serializeData(data, payloadType) {
} else if (payloadType === 'dictionary') {
const jsonStr = JSON.stringify(data);
return Buffer.from(jsonStr, 'utf8');
} else if (payloadType === 'table') {
} else if (payloadType === 'arrowtable') {
// Convert array of objects to Arrow IPC format
if (!Array.isArray(data) || data.length === 0) {
throw new Error('Table data must be a non-empty array of objects');
throw new Error('Arrow table data must be a non-empty array of objects');
}
return serializeArrowTable(data);
} else if (payloadType === 'jsontable') {
// Serialize array of objects to JSON format
if (!Array.isArray(data)) {
throw new Error('JSON table data must be an array');
}
const jsonStr = JSON.stringify(data);
return Buffer.from(jsonStr, 'utf8');
} else if (payloadType === 'image') {
if (data instanceof Uint8Array || Buffer.isBuffer(data)) {
return Buffer.from(data);
@@ -159,7 +168,7 @@ async function deserializeData(data, payloadType, correlationId) {
logTrace(correlationId, `deserializeData: type=${payloadType}, bufferLength=${buffer.length}`);
// Debug: Show first 20 bytes in hex for binary data
if (payloadType === 'table' || payloadType === 'image' || payloadType === 'binary') {
if (payloadType === 'arrowtable' || payloadType === 'jsontable' || payloadType === 'image' || payloadType === 'binary') {
const hexPreview = buffer.slice(0, 20).toString('hex');
logTrace(correlationId, `deserializeData: First 20 bytes (hex): ${hexPreview}`);
}
@@ -173,7 +182,7 @@ async function deserializeData(data, payloadType, correlationId) {
const result = JSON.parse(jsonStr);
logTrace(correlationId, `deserializeData: dictionary keys=${Object.keys(result).join(', ')}`);
return result;
} else if (payloadType === 'table') {
} else if (payloadType === 'arrowtable') {
logTrace(correlationId, `deserializeData: Attempting Arrow table deserialization`);
// Debug: Check available arrow methods
@@ -205,6 +214,11 @@ async function deserializeData(data, payloadType, correlationId) {
}
throw new Error(`Unable to deserialize Arrow table: neither tableFromRawBytes nor tableFromIPC worked`);
} else if (payloadType === 'jsontable') {
const jsonStr = buffer.toString('utf8');
const result = JSON.parse(jsonStr);
logTrace(correlationId, `deserializeData: jsontable result length=${Array.isArray(result) ? result.length : 'N/A'}`);
return result;
} else if (payloadType === 'image') {
logTrace(correlationId, `deserializeData: image buffer length=${buffer.length}`);
return buffer;
@@ -435,12 +449,20 @@ function buildEnvelope(subject, payloads, options) {
* @returns {Object} Payload object
*/
function buildPayload(dataname, payloadType, payloadBytes, transport, data) {
// Determine encoding based on payload type (matching Julia implementation)
let encoding = 'base64';
if (payloadType === 'jsontable') {
encoding = 'json';
} else if (payloadType === 'arrowtable') {
encoding = 'arrow-ipc';
}
return {
id: crypto.randomUUID(),
dataname,
payload_type: payloadType,
transport,
encoding: transport === 'direct' ? 'base64' : 'none',
encoding,
size: payloadBytes.byteLength,
data,
metadata: transport === 'direct' ? { payload_bytes: payloadBytes.byteLength } : {}
@@ -457,6 +479,7 @@ function buildPayload(dataname, payloadType, payloadBytes, transport, data) {
*
* @param {string} subject - NATS subject to publish the message to
* @param {Array} data - List of [dataname, data, type] tuples to send
* - type: "text", "dictionary", "arrowtable", "jsontable", "image", "audio", "video", "binary"
* @param {Object} options - Optional configuration
* @param {string} [options.broker_url=DEFAULT_BROKER_URL] - URL of the NATS server
* @param {string} [options.fileserver_url=DEFAULT_FILESERVER_URL] - URL of the HTTP file server
@@ -488,7 +511,7 @@ function buildPayload(dataname, payloadType, payloadBytes, transport, data) {
* "/test",
* [
* ["dataname1", data1, "dictionary"],
* ["dataname2", data2, "table"]
* ["dataname2", data2, "arrowtable"]
* ],
* { broker_url: "nats://localhost:4222" }
* );