text: import{columnIndexOf,columnMinValue,columnMaxValue,columnMinDiff,columnExtents,columnUnique,addColumnsSchema,addColumnsData,isUTCEnabled as _isUTCEnabled}from"./utils/datatable-utils";import{addHandler,triggerEvent,removeHandler}from"./utils/event-handler";var UNDEF;var DataTable=function(){function DataTable(dataStore,data,schema,config,parentTable,opsFunnel,id){this._dataStore=dataStore;this._parentTable=parentTable;this._children=[];this._childrenTableIDs=[];this._opsFunnel=opsFunnel;this._data=data||[];this._schema=schema;this._config=config;this._id=id;var counter=1,baseID;if(!this._id){baseID=this._parentTable&&this._parentTable._id?this._parentTable._id:"table_1";this._id=baseID+"_"+counter}if(this._parentTable){while(this._parentTable._childrenTableIDs.includes(this._id)){if(baseID){this._id=baseID+"_"+ ++counter}else{this._id=this._id+"_1"}}this._parentTable._children.push(this);this._parentTable._childrenTableIDs.push(this._id)}this._result=null}var _proto=DataTable.prototype;_proto._appendRows=function _appendRows(rows){var childrenLength=this._children&&this._children.length||0,schemaLength=this._result&&this._result.schema.length||0;if(schemaLength)this._calcColumns=[];for(var i=0;i<schemaLength;i++){if(this._result.schema[i].calcFn){this._calcColumns.push(this._result.schema[i])}}if(this._result){delete this._result}for(var _i=0;_i<childrenLength;_i++){this._children[_i]._appendRows(rows)}};_proto.count=function count(){var result=this._executeFunnel();return result.data.length};_proto.getSchema=function getSchema(){var result=this._executeFunnel();return result.schema};_proto.getID=function getID(){return this._id};_proto.getDataStore=function getDataStore(){return this._dataStore};_proto.getChildren=function getChildren(id){if(id){for(var i=0;i<this._children.length;i++){if(this._children[i]._id===id){return this._children[i]}}return null}return this._children};_proto.getData=function getData(_offset,_numberOfItems){var offset=_offset,numberOfItems=_numberOfItems,result;offset=offset||0;numberOfItems=numberOfItems&&(typeof numberOfItems==="string"||numberOfItems instanceof String)||numberOfItems===null?UNDEF:numberOfItems;result=this._executeFunnel();return{data:result.data&&result.data.slice(offset,numberOfItems&&numberOfItems>0?offset+numberOfItems:numberOfItems),schema:result.schema}};_proto.dispose=function dispose(){var instance=this,childrenLength=instance._children&&instance._children.length||0;if(instance._parentTable&&instance._parentTable._children){var i;for(i=0;i<instance._parentTable._children.length;i++){if(typeof instance._id!=="undefined"&&instance._id===instance._parentTable._children[i]._id){break}}if(i!==instance._parentTable._children.length){instance._parentTable._children.splice(i,1)}}delete instance._dataStore;delete instance._parentTable;delete instance._opsFunnel;delete instance._data;delete instance._schema;delete instance._config;delete instance._result;delete instance._id;for(var _i2=childrenLength-1;_i2>=0;_i2--){instance._children[_i2].dispose()}delete instance._children;delete instance._childrenTableIDs;instance._trigger("disposed");delete instance._evtHandlers;instance=null};_proto.min=function min(columnName){var dtData=this.getData();return columnMinValue(columnName,dtData.data,dtData.schema)};_proto.max=function max(columnName){var dtData=this.getData();return columnMaxValue(columnName,dtData.data,dtData.schema)};_proto.unique=function unique(columnName){var dtData=this.getData();return columnUnique(columnName,dtData.data,dtData.schema)};_proto.extents=function extents(columnName){var dtData=this.getData();return columnExtents(columnName,dtData.data,dtData.schema)};_proto.addColumns=function addColumns(){for(var _len=arguments.length,columnConfigs=new Array(_len),_key=0;_key<_len;_key++){columnConfigs[_key]=arguments[_key]}var columnConfigsLen=columnConfigs.length;if(columnConfigsLen>0){this._calcColumns=this._calcColumns||[];for(var i=0;i<columnConfigsLen;i++){if(!columnConfigs[i].name)throw new Error("name is required in column "+(i+1));if(columnConfigs[i].calcFn&&!(columnConfigs[i].calcFn instanceof Function))throw new Error("calcFn must be a function in column "+(i+1));if(!columnConfigs[i].calcFn){columnConfigs[i].calcFn=function(){return UNDEF}}this._calcColumns.push(Object.assign({},columnConfigs[i]))}}this._trigger("updated",columnConfigs)};_proto.query=function query(_operations){var operations=_operations,dataTable;if(operations&&operations.constructor!==Array){operations=[operations]}dataTable=new DataTable(this._dataStore,this._data,this._schema,this._config,this,operations);return dataTable};_proto.indexOf=function indexOf(columnName){var result=this._executeFunnel();return columnIndexOf(columnName,result.schema)};_proto.on=function on(eventName,handlers){addHandler(eventName,handlers,this)};_proto.off=function off(eventName,handlers){removeHandler(eventName,handlers,this)};_proto._trigger=function _trigger(eventName,data){triggerEvent(eventName,this,data)};_proto._executeFunnel=function _executeFunnel(){if(!this._result){if(this._opsFunnel){var parentResult,data,schema,config,funnelLen;parentResult=this._parentTable._executeFunnel();data=parentResult.data.slice(0);schema=parentResult.schema.slice(0);config=Object.assign({},parentResult.config);funnelLen=this._opsFunnel.length;for(var i=0;i<funnelLen;i++){if(this._opsFunnel[i]&&this._opsFunnel[i].fn){var result=this._opsFunnel[i].fn(data,schema,config);data=result.generatorFn?result.generatorFn():result.data;schema=result.schema;config=Object.assign(config,result.config);if(config.indexBy===UNDEF)config.enableIndex=false}}this._result={data:data,schema:schema,config:config}}else{this._result={data:this._data,schema:this._schema,config:this._config}}}if(this._calcColumns&&this._calcColumns.length>0){var columnConfigs=addColumnsSchema(this._result.schema,this._calcColumns);this._result.schema=columnConfigs.schema;this._result.data=addColumnsData(this._result.data,this._result.schema,columnConfigs.calcColumns);delete this._calcColumns}return this._result};_proto._flushResult=function _flushResult(data){var schemaLength=this._result&&this._result.schema.length||0;if(schemaLength)this._calcColumns=[];for(var i=0;i<schemaLength;i++){if(this._result.schema[i].calcFn){this._calcColumns.push(this._result.schema[i])}}if(this._result){this._result=null}if(this._children){for(var _i3=0;_i3<this._children.length;_i3++){this._children[_i3]._flushResult(data)}}this._trigger("resultFlushed",data)};_proto.propagate=function propagate(payload){this.getDataStore()._propagate({trigger:this,payload:payload})};_proto._payloadReceiver=function _payloadReceiver(payload){var childrenLength=this._children&&this._children.length||0;if(payload&&payload.trigger&&payload.trigger!==this){this._trigger("payloadReceived",payload)}for(var i=0;i<childrenLength;i++){this._children[i]._payloadReceiver(payload)}};_proto.getMinDiff=function getMinDiff(columnName){var dtData=this.getData();return columnMinDiff(columnName,dtData.data,dtData.schema,this._config.indexBy)};_proto.isUTCEnabled=function isUTCEnabled(columnName){return _isUTCEnabled(columnName,this.getSchema())};return DataTable}();export{DataTable as default};