h54s
Version:
HTML5 Data Adapter for SAS
54 lines (46 loc) • 1.6 kB
JavaScript
const h54sError = require('../error.js');
/*
* h54s tables object constructor
* @constructor
*
*@param {array} table - Table added when object is created
*@param {string} macroName - macro name
*@param {number} parameterThreshold - size of data objects sent to SAS
*
*/
function Tables(table, macroName, parameterThreshold) {
this._tables = {};
this._parameterThreshold = parameterThreshold || 30000;
Tables.prototype.add.call(this, table, macroName);
}
/*
* Add table to tables object
* @param {array} table - Array of table objects
* @param {string} macroName - Sas macro name
*
*/
Tables.prototype.add = function(table, macroName) {
if(table && macroName) {
if(!(table instanceof Array)) {
throw new h54sError('argumentError', 'First argument must be array');
}
if(typeof macroName !== 'string') {
throw new h54sError('argumentError', 'Second argument must be string');
}
if(!isNaN(macroName[macroName.length - 1])) {
throw new h54sError('argumentError', 'Macro name cannot have number at the end');
}
} else {
throw new h54sError('argumentError', 'Missing arguments');
}
const result = this._utils.convertTableObject(table, this._parameterThreshold);
const tableArray = [];
tableArray.push(JSON.stringify(result.spec));
for (let numberOfTables = 0; numberOfTables < result.data.length; numberOfTables++) {
const outString = JSON.stringify(result.data[numberOfTables]);
tableArray.push(outString);
}
this._tables[macroName] = tableArray;
};
Tables.prototype._utils = require('./utils.js');
module.exports = Tables;