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K,KAAK,YAAY,SAAS,EAAQ,EAAG,GACrD,IACJ,IAMR,IAAI,eAAiB,IAAI,gBACzB,QAAQ,KAAO,SAAU,GACrB,OAAO,eAAe,MAAM,EAChC,EACsB,oBAAX,SACP,OAAO,YAAc,CACjB,KAAM,QAAQ,KACd,gBAAiB","file":"/npm/nano-sql@1.8.5/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/nano-sql@1.8.5/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var __assign = (this && this.__assign) || function () {\n    __assign = Object.assign || function(t) {\n        for (var s, i = 1, n = arguments.length; i < n; i++) {\n            s = arguments[i];\n            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n                t[p] = s[p];\n        }\n        return t;\n    };\n    return __assign.apply(this, arguments);\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar lie_ts_1 = require(\"lie-ts\");\nvar std_query_1 = require(\"./query/std-query\");\nvar transaction_1 = require(\"./query/transaction\");\nvar really_small_events_1 = require(\"really-small-events\");\nvar utilities_1 = require(\"./utilities\");\nvar index_1 = require(\"./database/index\");\nvar history_plugin_1 = require(\"./history-plugin\");\nvar levenshtein = require(\"levenshtein-edit-distance\");\nvar observable_1 = require(\"./observable\");\nvar VERSION = 1.83;\n// uglifyJS fix\nvar str = [\"_util\", \"_ttl\"];\n/**\n * The primary abstraction class, there is no database implimintation code here.\n * Just events, quries and filters.\n *\n * @export\n * @class NanoSQLInstance\n */\nvar NanoSQLInstance = /** @class */ (function () {\n    function NanoSQLInstance() {\n        this.version = VERSION;\n        this._onConnectedCallBacks = [];\n        var t = this;\n        t.isConnected = false;\n        t.focused = true;\n        t._actions = {};\n        t._views = {};\n        t.dataModels = {};\n        t._events = [\"*\", \"change\", \"delete\", \"upsert\", \"drop\", \"select\", \"error\", \"peer-change\"];\n        t._hasEvents = {};\n        t.tableNames = [];\n        t.plugins = [];\n        t.hasPK = {};\n        t.skipPurge = {};\n        t.toRowFns = {};\n        t._tablePKs = {};\n        t._tablePKTypes = {};\n        t.toColFns = {};\n        t.toColRules = {};\n        t.rowFilters = {};\n        t.peers = [];\n        t.peerEvents = [];\n        t.pid = utilities_1.uuid();\n        t._randoms = [];\n        // t._queryPool = [];\n        // t._queryPtr = 0;\n        t._randomPtr = 0;\n        t.hasAnyEvents = false;\n        for (var i = 0; i < 1000; i++) {\n            t._randoms.push(utilities_1.random16Bits());\n            // t._queryPool.push(new _NanoSQLQuery(t));\n        }\n        t._callbacks = {};\n        t._callbacks[\"*\"] = new really_small_events_1.ReallySmallEvents();\n        t.iB = new index_1.NanoSQLDefaultBackend();\n        var instanceConnectArgs = {\n            models: {},\n            actions: {},\n            views: {},\n            config: {},\n            parent: this\n        };\n        if (t.iB.willConnect) {\n            t.iB.willConnect(instanceConnectArgs, function () {\n                if (t.iB.didConnect) {\n                    t.iB.didConnect(instanceConnectArgs, function () {\n                    });\n                }\n            });\n        }\n        this._checkTTL = this._checkTTL.bind(this);\n    }\n    NanoSQLInstance.prototype.rowFilter = function (callback) {\n        this.rowFilters[this.sTable] = callback;\n        return this;\n    };\n    NanoSQLInstance.prototype.toColumn = function (columnFns) {\n        if (!this.toColFns[this.sTable]) {\n            this.toColFns[this.sTable] = {};\n        }\n        this.toColFns[this.sTable] = columnFns;\n        return this;\n    };\n    NanoSQLInstance.prototype.toRow = function (columnFns) {\n        if (!this.toRowFns[this.sTable]) {\n            this.toRowFns[this.sTable] = {};\n        }\n        this.toRowFns[this.sTable] = columnFns;\n        return this;\n    };\n    /**\n     * nanoSQL generates 50 random 16 bit strings on every launch.\n     * If you don't need true randomness you can use this function to get a psudorandom 16 bit string.\n     * Performance is orders of a magnitude faster since no random number generator is needed.\n     *\n     * @returns {string}\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.fastRand = function () {\n        this._randomPtr++;\n        if (this._randomPtr >= this._randoms.length) {\n            this._randomPtr = 0;\n        }\n        return this._randoms[this._randomPtr];\n    };\n    /**\n     * Remove TTL from specific row\n     *\n     * @param {*} primaryKey\n     * @returns {Promise<any>}\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.clearTTL = function (primaryKey) {\n        var k = this.sTable + \".\" + primaryKey;\n        return this.query(\"delete\").where([\"key\", \"=\", k]).manualExec({ table: \"_ttl\" });\n    };\n    /**\n     * Check when a given row is going to expire.\n     *\n     * @param {*} primaryKey\n     * @returns {Promise<any>}\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.expires = function (primaryKey) {\n        var _this = this;\n        return new Promise(function (res, rej) {\n            var k = _this.sTable + \".\" + primaryKey;\n            _this.query(\"select\").where([\"key\", \"=\", k]).manualExec({ table: \"_ttl\" }).then(function (rows) {\n                if (!rows.length) {\n                    res({ time: -1, cols: [] });\n                }\n                else {\n                    res({ time: (rows[0].date - Date.now()) / 1000, cols: rows[0].cols });\n                }\n            });\n        });\n    };\n    NanoSQLInstance.prototype._checkTTL = function () {\n        var _this = this;\n        if (this._ttlTimer) {\n            clearTimeout(this._ttlTimer);\n        }\n        var page = 0;\n        var nextTTL = 0;\n        var getPage = function () {\n            _this.query(\"select\").range(20, 20 * page).manualExec({ table: \"_ttl\" }).then(function (rows) {\n                if (!rows.length) {\n                    if (nextTTL) {\n                        _this._ttlTimer = setTimeout(_this._checkTTL, nextTTL - Date.now());\n                    }\n                    return;\n                }\n                utilities_1.fastCHAIN(rows, function (row, i, next) {\n                    if (row.date < Date.now()) {\n                        var clearTTL = function () {\n                            _this.query(\"delete\").where([\"key\", \"=\", row.key]).manualExec({ table: \"_ttl\" }).then(next);\n                        };\n                        var rowData = row.key.split(\".\");\n                        var table = rowData[0];\n                        var key = [\"float\", \"int\", \"number\"].indexOf(_this._tablePKTypes[table]) === -1 ? rowData[1] : parseFloat(rowData[1]);\n                        if (row.cols.length) {\n                            var upsertObj_1 = {};\n                            row.cols.forEach(function (col) {\n                                upsertObj_1[col] = null;\n                            });\n                            _this.query(\"upsert\", upsertObj_1).where([_this._tablePKs[table], \"=\", key]).manualExec({ table: table }).then(clearTTL);\n                        }\n                        else {\n                            _this.query(\"delete\").where([_this._tablePKs[table], \"=\", key]).manualExec({ table: table }).then(clearTTL);\n                        }\n                    }\n                    else {\n                        nextTTL = Math.max(nextTTL, row.date);\n                        next();\n                    }\n                }).then(function () {\n                    page++;\n                    getPage();\n                });\n            });\n        };\n        getPage();\n    };\n    /**\n     * Changes the table pointer to a new table.\n     *\n     * @param {string} [table]\n     * @returns {NanoSQLInstance}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.table = function (table) {\n        if (table)\n            this.sTable = table;\n        return this;\n    };\n    NanoSQLInstance.prototype.getPeers = function () {\n        return JSON.parse(localStorage.getItem(\"nsql-peers-\" + this.id) || \"[]\");\n    };\n    /**\n     * Inits the backend database for use.\n     *\n     * Optionally include a custom database driver, otherwise the built in memory driver will be used.\n     *\n     * @param {NanoSQLBackend} [backend]\n     * @returns {(Promise<Object | string>)}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.connect = function () {\n        var _this = this;\n        var t = this;\n        return new Promise(function (res, rej) {\n            var connectArgs = {\n                models: t.dataModels,\n                actions: t._actions,\n                views: t._views,\n                config: t._config,\n                parent: _this,\n            };\n            connectArgs.models[str[0]] = [\n                { key: \"key\", type: \"string\", props: [\"pk()\", \"ai()\"] },\n                { key: \"value\", type: \"any\" }\n            ];\n            connectArgs.models[str[1]] = [\n                { key: \"key\", type: \"string\", props: [\"pk()\"] },\n                { key: \"table\", type: \"string\" },\n                { key: \"cols\", type: \"string[]\" },\n                { key: \"date\", type: \"number\" }\n            ];\n            // if history is enabled, turn on the built in history plugin\n            if (t._config && t._config.history) {\n                _this.use(new history_plugin_1._NanoSQLHistoryPlugin(t._config.historyMode));\n            }\n            // If the db mode is not set to disable, add default store to the end of the plugin chain\n            if (!t._config || t._config.mode !== false) {\n                _this.use(new index_1.NanoSQLDefaultBackend());\n            }\n            if (typeof window !== \"undefined\" && _this._config && _this._config.peer) {\n                _this.peerMode = true;\n            }\n            utilities_1.fastCHAIN(t.plugins, function (p, i, nextP) {\n                if (p.willConnect) {\n                    p.willConnect(connectArgs, function (newArgs) {\n                        connectArgs = newArgs;\n                        nextP();\n                    });\n                }\n                else {\n                    nextP();\n                }\n            }).then(function () {\n                t.dataModels = connectArgs.models;\n                t._actions = connectArgs.actions;\n                t._views = connectArgs.views;\n                t._config = connectArgs.config;\n                Object.keys(t.dataModels).forEach(function (table) {\n                    var hasWild = false;\n                    t.dataModels[table] = t.dataModels[table].filter(function (model) {\n                        if (model.key === \"*\" && model.type === \"*\") {\n                            hasWild = true;\n                            return false;\n                        }\n                        return true;\n                    });\n                    t.skipPurge[table] = hasWild;\n                });\n                t.plugins.forEach(function (plugin) {\n                    if (plugin.didExec) {\n                        t.pluginHasDidExec = true;\n                    }\n                });\n                t.tableNames = Object.keys(t.dataModels);\n                var completeConnect = function () {\n                    utilities_1.fastALL(t.plugins, function (p, i, nextP) {\n                        if (p.getId && !_this.id) {\n                            _this.id = p.getId();\n                        }\n                        if (p.didConnect) {\n                            p.didConnect(connectArgs, function () {\n                                nextP();\n                            });\n                        }\n                        else {\n                            nextP();\n                        }\n                    }).then(function () {\n                        // handle peer features with other browser windows/tabs\n                        if (_this.peerMode) {\n                            var counter_1 = 0;\n                            if (!_this.id) {\n                                _this.id = _this.pid;\n                            }\n                            // Append this peer to the network\n                            _this.peers = _this.getPeers();\n                            _this.peers.unshift(_this.pid);\n                            localStorage.setItem(\"nsql-peers-\" + _this.id, JSON.stringify(_this.peers));\n                            // When localstorage changes we may need to possibly update the peer list\n                            // or possibly respond to an event from another peer\n                            window.addEventListener(\"storage\", function (e) {\n                                // peer list updated\n                                if (e.key === \"nsql-peers-\" + _this.id) {\n                                    _this.peers = _this.getPeers();\n                                }\n                                // recieved event from another peer\n                                if (e.key && e.key.indexOf(_this.pid + \".\") === 0) {\n                                    localStorage.removeItem(e.key);\n                                    var ev_1 = JSON.parse(e.newValue || \"{}\");\n                                    _this.peerEvents.push(ev_1.query.queryID || \"\");\n                                    _this.triggerEvent(__assign({}, ev_1, { types: [\"peer-change\"] }));\n                                    lie_ts_1.setFast(function () {\n                                        _this.triggerEvent(ev_1);\n                                    });\n                                }\n                                // the \"master\" peer checks to make sure all peers have been\n                                // cleaning up their mess every 50 requests, if they aren't they\n                                // are removed. Keeps localStorage from filling up accidentally.\n                                counter_1++;\n                                if (counter_1 > 50 && _this.peers[0] === _this.pid) {\n                                    counter_1 = 0;\n                                    var len = localStorage.length;\n                                    var peerKeys_1 = {};\n                                    while (len--) {\n                                        var key = localStorage.key(len);\n                                        // only grab events\n                                        var keyMatch = key ? key.match(/\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{8}/gmi) : null;\n                                        if (key && keyMatch) {\n                                            var peerID = (keyMatch || [\"\"])[0];\n                                            if (!peerKeys_1[peerID]) {\n                                                peerKeys_1[peerID] = [];\n                                            }\n                                            peerKeys_1[peerID].push(key);\n                                        }\n                                    }\n                                    Object.keys(peerKeys_1).forEach(function (peerID) {\n                                        // purge peers that aren't cleaning up their mess (and thus probably gone)\n                                        if (peerKeys_1[peerID].length > 10) {\n                                            _this.peers = _this.peers.filter(function (p) { return p !== peerID; });\n                                            peerKeys_1[peerID].forEach(function (key) {\n                                                localStorage.removeItem(key);\n                                            });\n                                            localStorage.setItem(\"nsql-peers-\" + _this.id, JSON.stringify(_this.peers));\n                                        }\n                                    });\n                                }\n                            });\n                            window.onblur = function () {\n                                _this.focused = false;\n                            };\n                            // on focus we set this nsql to focused and move it's peer position\n                            // to the front\n                            window.onfocus = function () {\n                                // set this peer to master on focus\n                                _this.peers = _this.peers.filter(function (p) { return p !== _this.pid; });\n                                _this.peers.unshift(_this.pid);\n                                localStorage.setItem(\"nsql-peers-\" + _this.id, JSON.stringify(_this.peers));\n                                _this.focused = true;\n                            };\n                            // send events to the peer network\n                            exports.nSQL(\"*\").on(\"change\", function (ev) {\n                                var idxOf = _this.peerEvents.indexOf(ev.query.queryID || \"\");\n                                if (idxOf !== -1) {\n                                    _this.peerEvents.splice(idxOf, 1);\n                                    return;\n                                }\n                                _this.peers.filter(function (p) { return p !== _this.pid; }).forEach(function (p) {\n                                    localStorage.setItem(p + \".\" + ev.query.queryID, JSON.stringify(ev));\n                                });\n                            });\n                            // Remove self from peer network\n                            window.addEventListener(\"beforeunload\", function () {\n                                _this.peers = _this.peers.filter(function (p) { return p !== _this.pid; });\n                                localStorage.setItem(\"nsql-peers-\" + _this.id, JSON.stringify(_this.peers));\n                                return false;\n                            });\n                        }\n                        t.isConnected = true;\n                        if (t._onConnectedCallBacks.length) {\n                            t._onConnectedCallBacks.forEach(function (cb) { return cb(); });\n                            t._onConnectedCallBacks = [];\n                        }\n                        _this._checkTTL();\n                        res(t.tableNames);\n                    });\n                };\n                var updateDBVersion = function () {\n                    if (typeof _this.getConfig().version !== \"undefined\") {\n                        t.query(\"select\").where([\"key\", \"=\", \"db-version\"]).manualExec({ table: \"_util\" }).then(function (rows) {\n                            if (!rows.length) {\n                                t.query(\"upsert\", { key: \"db-version\", value: _this.getConfig().version }).manualExec({ table: \"_util\" }).then(function () {\n                                    completeConnect();\n                                });\n                                return;\n                            }\n                            var version = rows.length ? rows[0].value : _this.getConfig().version;\n                            var upgrade = function () {\n                                if (version === _this.getConfig().version) {\n                                    completeConnect();\n                                }\n                                else {\n                                    if (!_this.getConfig().onVersionUpdate) {\n                                        version = _this.getConfig().version;\n                                        upgrade();\n                                        return;\n                                    }\n                                    _this.getConfig().onVersionUpdate(version).then(function (newVersion) {\n                                        version = newVersion;\n                                        lie_ts_1.setFast(upgrade);\n                                    }).catch(rej);\n                                }\n                            };\n                            upgrade();\n                        });\n                    }\n                    else {\n                        completeConnect();\n                    }\n                };\n                var updateNSQLVersion = function (rebuildIDX) {\n                    t.query(\"upsert\", { key: \"version\", value: t.version }).manualExec({ table: \"_util\" }).then(function () {\n                        if (rebuildIDX) {\n                            t.extend(\"beforeConn\", \"rebuild_idx\").then(function () {\n                                updateDBVersion();\n                            });\n                        }\n                        else {\n                            updateDBVersion();\n                        }\n                    });\n                };\n                t.query(\"select\").where([\"key\", \"=\", \"version\"]).manualExec({ table: \"_util\" }).then(function (rows) {\n                    if (!rows.length) {\n                        // new database or an old one that needs indexes rebuilt\n                        updateNSQLVersion(true);\n                    }\n                    else {\n                        if (rows[0].value <= 1.21) { // secondary indexes need to be rebuilt before 1.21\n                            updateNSQLVersion(true);\n                        }\n                        else if (rows[0].value < VERSION) {\n                            updateNSQLVersion(false);\n                        }\n                        else {\n                            updateDBVersion();\n                        }\n                    }\n                });\n            });\n        });\n    };\n    /**\n     * Get all actions for a given table\n     * =\n     * @param {string} table\n     * @returns\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.getActions = function (table) {\n        return this._actions[table].map(function (a) {\n            return {\n                name: a.name,\n                args: a.args\n            };\n        });\n    };\n    /**\n     * Get all views for a given table\n     *\n     * @param {string} table\n     * @returns\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.getViews = function (table) {\n        return this._views[table].map(function (a) {\n            return {\n                name: a.name,\n                args: a.args\n            };\n        });\n    };\n    /**\n     * Grab a copy of the database config object.\n     *\n     * @returns\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.getConfig = function () {\n        return (this._config || {});\n    };\n    /**\n     * Set the action/view filter function.  Called *before* the action/view is sent to the datastore\n     *\n     * @param {IActionViewMod} filterFunc\n     * @returns\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.avFilter = function (filterFunc) {\n        this._AVMod = filterFunc;\n        return this;\n    };\n    NanoSQLInstance.prototype.use = function (plugin) {\n        return this.plugins.push(plugin), this;\n    };\n    /**\n     * Adds an event listener to the selected database table.\n     *\n     * @param {(\"change\"|\"delete\"|\"upsert\"|\"drop\"|\"select\"|\"error\")} actions\n     * @param {Function} callBack\n     * @returns {NanoSQLInstance}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.on = function (actions, callBack) {\n        var t = this;\n        var l = t.sTable;\n        var i = t._events.length;\n        var a = actions.split(\" \");\n        if (Array.isArray(l))\n            return this;\n        if (!t._callbacks[l]) { // Handle the event handler being called before the database has connected\n            t._callbacks[l] = new really_small_events_1.ReallySmallEvents();\n        }\n        i = a.length;\n        while (i--) {\n            if (t._events.indexOf(a[i]) !== -1) {\n                t._callbacks[l].on(a[i], callBack);\n            }\n        }\n        return t._refreshEventChecker();\n    };\n    /**\n     * Remove a specific event handler from being triggered anymore.\n     *\n     * @param {Function} callBack\n     * @returns {NanoSQLInstance}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.off = function (actions, callBack) {\n        var t = this;\n        var a = actions.split(\" \");\n        var i = a.length;\n        var l = t.sTable;\n        if (Array.isArray(l))\n            return this;\n        while (i--) {\n            if (t._events.indexOf(a[i]) !== -1) {\n                t._callbacks[l].off(a[i], callBack);\n            }\n        }\n        return t._refreshEventChecker();\n    };\n    NanoSQLInstance.prototype._refreshEventChecker = function () {\n        var _this = this;\n        this._hasEvents = {};\n        Object.keys(this._callbacks).concat([\"*\"]).forEach(function (table) {\n            _this._hasEvents[table] = _this._events.reduce(function (prev, cur) {\n                return prev + (_this._callbacks[table] && _this._callbacks[table].eventListeners[cur] ? _this._callbacks[table].eventListeners[cur].length : 0);\n            }, 0) > 0;\n        });\n        this.hasAnyEvents = false;\n        Object.keys(this._hasEvents).forEach(function (key) {\n            _this.hasAnyEvents = _this.hasAnyEvents || _this._hasEvents[key];\n        });\n        return this;\n    };\n    /**\n     * Declare the data model for the current selected table.\n     *\n     * Please reference the DataModel interface for how to impliment this, a quick example:\n     *\n     * ```ts\n     * .model([\n     *  {key:\"id\",type:\"int\",props:[\"ai\",\"pk\"]} //auto incriment and primary key\n     *  {key:\"name\",type:\"string\"}\n     * ])\n     * ```\n     *\n     * @param {Array<DataModel>} dataModel\n     * @returns {NanoSQLInstance}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.model = function (dataModel, props, ignoreSanityCheck) {\n        var _this = this;\n        var t = this;\n        var l = t.sTable;\n        if (Array.isArray(l))\n            return this;\n        if (!t._callbacks[l]) {\n            t._callbacks[l] = new really_small_events_1.ReallySmallEvents();\n        }\n        var hasPK = false;\n        if (!ignoreSanityCheck) {\n            // validate table name and data model\n            var types = [\"string\", \"safestr\", \"timeId\", \"timeIdms\", \"uuid\", \"int\", \"float\", \"number\", \"array\", \"map\", \"bool\", \"blob\", \"any\"];\n            if (types.indexOf(l.replace(/\\W/gmi, \"\")) !== -1 || l.indexOf(\"_\") === 0 || l.match(/[\\(\\)\\]\\[\\.]/g) !== null) {\n                throw Error(\"Invalid Table Name! https://docs.nanosql.io/setup/data-models\");\n            }\n            (dataModel || []).forEach(function (model) {\n                if (model.key.match(/[\\(\\)\\]\\[\\.]/g) !== null || model.key.indexOf(\"_\") === 0) {\n                    throw Error(\"Invalid Data Model! https://docs.nanosql.io/setup/data-models\");\n                }\n            });\n        }\n        t.toColRules[l] = {};\n        (dataModel || []).forEach(function (model) {\n            if (model.props) {\n                model.props.forEach(function (prop) {\n                    // old format: from=>fn(arg1, arg2);\n                    if (prop.indexOf(\"from=>\") !== -1 && prop.indexOf(\"(\") !== -1) {\n                        var fnName = prop.replace(\"from=>\", \"\").split(\"(\").shift();\n                        var fnArgs = prop.replace(\"from=>\", \"\").split(\"(\").pop().replace(\")\", \"\").split(\",\").map(function (c) { return c.trim(); });\n                        t.toColRules[l][model.key] = [fnName].concat(fnArgs);\n                    }\n                    // new format: toColumn.fn(arg1, arg2);\n                    if (prop.indexOf(\"toColumn.\") === 0) {\n                        var fnName = prop.replace(/toColumn\\.(.*)\\(.*\\)/gmi, \"$1\");\n                        var fnArgs = prop.replace(/toColumn\\..*\\((.*)\\)/gmi, \"$1\").split(\",\").map(function (c) { return c.trim(); });\n                        t.toColRules[l][model.key] = [fnName].concat(fnArgs);\n                    }\n                });\n            }\n            if (model.props && utilities_1.intersect([\"pk\", \"pk()\"], model.props)) {\n                _this._tablePKs[l] = model.key;\n                _this._tablePKTypes[l] = model.type;\n                hasPK = true;\n            }\n        });\n        this.hasPK[l] = hasPK;\n        if (!hasPK) {\n            this._tablePKs[l] = \"_id_\";\n            dataModel.unshift({ key: \"_id_\", type: \"uuid\", props: [\"pk()\"] });\n        }\n        t.dataModels[l] = dataModel;\n        t._views[l] = [];\n        t._actions[l] = [];\n        return t;\n    };\n    /**\n     * Declare the views for the current selected table.  Must be called before connect()\n     *\n     * Views are created like this:\n     *\n     * ```ts\n     * .views([\n     *  {\n     *      name:\"view-name\",\n     *      args: [\"array\",\"of\",\"arguments\"],\n     *      call: function(args) {\n     *          // Because of our \"args\" array the args input of this function will look like this:\n     *          // NanoSQL will not let any other arguments into this function.\n     *          args:{\n     *              array:'',\n     *              of:'',\n     *              arguments:''\n     *          }\n     *          //We can use them in our query\n     *          return this.query('select').where(['name','IN',args.array]).exec();\n     *      }\n     *  }\n     * ])\n     * ```\n     *\n     * Then later in your app..\n     *\n     * ```ts\n     * NanoSQL(\"users\").getView(\"view-name\",{array:'',of:\"\",arguments:\"\"}).then(function(result) {\n     *  console.log(result) <=== result of your view will be there.\n     * })\n     * ```\n     *\n     * Optionally you can type cast the arguments at run time typescript style, just add the types after the arguments in the array.  Like this:\n     *\n     * ```ts\n     * .views[{\n     *      name:...\n     *      args:[\"name:string\",\"balance:float\",\"active:bool\"]\n     *      call:...\n     * }]\n     * ```\n     *\n     * NanoSQL will force the arguments passed into the function to those types.\n     *\n     * Possible types are string, bool, float, int, map, array and bool.\n     *\n     * @param {Array<ActionOrView>} viewArray\n     * @returns {NanoSQLInstance}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.views = function (viewArray) {\n        if (Array.isArray(this.sTable))\n            return this;\n        return this._views[this.sTable] = viewArray, this;\n    };\n    /**\n     * Execute a specific view.  Refernece the \"views\" function for more description.\n     *\n     * Example:\n     * ```ts\n     * NanoSQL(\"users\").getView('view-name',{foo:\"bar\"}).then(function(result) {\n     *  console.log(result) <== view result.\n     * })\n     * ```\n     *\n     * @param {string} viewName\n     * @param {any} viewArgs\n     * @returns {(Promise<Array<Object>>)}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.getView = function (viewName, viewArgs) {\n        if (viewArgs === void 0) { viewArgs = {}; }\n        if (Array.isArray(this.sTable))\n            return new Promise(function (res, rej) { return rej(); });\n        return this._doAV(\"View\", this._views[this.sTable], viewName, viewArgs);\n    };\n    /**\n     * Declare the actions for the current selected table.  Must be called before connect()\n     *\n     * Actions are created like this:\n     * ```ts\n     * .actions([\n     *  {\n     *      name:\"action-name\",\n     *      args: [\"array\",\"of\",\"arguments\"],\n     *      call: function(args) {\n     *          // Because of our \"args\" array the args input of this function will look like this:\n     *          // NanoSQL will not let any other arguments into this function.\n     *          args:{\n     *              array:'',\n     *              of:'',\n     *              arguments:''\n     *          }\n     *          //We can use them in our query\n     *          return this.query(\"upsert\",{balance:0}).where(['name','IN',args.array]).exec();\n     *      }\n     *  }\n     * ])\n     * ```\n     *\n     * Then later in your app..\n     *\n     * ```ts\n     * NanoSQL(\"users\").doAction(\"action-name\",{array:'',of:\"\",arguments:\"\"}).then(function(result) {\n     *  console.log(result) <=== result of your view will be there.\n     * })\n     * ```\n     *\n     * Optionally you can type cast the arguments at run time typescript style, just add the types after the arguments in the array.  Like this:\n     * ```ts\n     * .actions[{\n     *      name:...\n     *      args:[\"name:string\",\"balance:float\",\"active:bool\"]\n     *      call:...\n     * }]\n     * ```\n     *\n     * NanoSQL will force the arguments passed into the function to those types.\n     *\n     * Possible types are string, bool, float, int, map, array and bool.\n     *\n     * @param {Array<ActionOrView>} actionArray\n     * @returns {NanoSQLInstance}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.actions = function (actionArray) {\n        if (Array.isArray(this.sTable))\n            return this;\n        return this._actions[this.sTable] = actionArray, this;\n    };\n    /**\n     * Init an action for the current selected table. Reference the \"actions\" method for more info.\n     *\n     * Example:\n     * ```ts\n     * NanoSQL(\"users\").doAction('action-name',{foo:\"bar\"}).then(function(result) {\n     *      console.log(result) <== result of your action\n     * });\n     * ```\n     *\n     * @param {string} actionName\n     * @param {any} actionArgs\n     * @returns {(Promise<Array<Object>>)}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.doAction = function (actionName, actionArgs) {\n        if (Array.isArray(this.sTable))\n            return new Promise(function (res, rej) { return rej(); });\n        return this._doAV(\"Action\", this._actions[this.sTable], actionName, actionArgs);\n    };\n    /**\n     * Adds a query filter to every request.\n     *\n     * @param {(args: DBExec) => Promise<IdbQuery>}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.queryFilter = function (queryMod) {\n        this.queryMod = queryMod;\n        return this;\n    };\n    /**\n     * Internal function to fire action/views.\n     *\n     * @private\n     * @param {(\"Action\"|\"View\")} AVType\n     * @param {ActionOrView[]} AVList\n     * @param {string} AVName\n     * @param {*} AVargs\n     * @returns {(Promise<Array<DBRow>|NanoSQLInstance>)}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype._doAV = function (AVType, AVList, AVName, AVargs) {\n        var _this = this;\n        var t = this;\n        var selAV = AVList.reduce(function (prev, cur) {\n            if (cur.name === AVName)\n                return cur;\n            return prev;\n        }, null);\n        if (!selAV) {\n            return new Promise(function (res, rej) { return rej(\"Action/View Not Found!\"); });\n        }\n        t._activeAV = AVName;\n        if (t._AVMod) {\n            return new Promise(function (res, rej) {\n                t._AVMod(_this.sTable, AVType, t._activeAV || \"\", AVargs, function (args) {\n                    selAV.call(selAV.args ? utilities_1.cleanArgs(selAV.args, args) : {}, t).then(res).catch(rej);\n                }, function (err) {\n                    rej(err);\n                });\n            });\n        }\n        else {\n            return selAV.call(selAV.args ? utilities_1.cleanArgs(selAV.args, AVargs) : {}, t);\n        }\n    };\n    /**\n     * Start a query into the current selected table.\n     * Possibl querys are \"select\", \"upsert\", \"delete\", and \"drop\";\n     *\n     * ### Select\n     *\n     * Select is used to pull a set of rows or other data from the table.\n     * When you use select the optional second argument of the query is an array of strings that allow you to show only specific columns.\n     *\n     * Examples:\n     * ```ts\n     * .query(\"select\") // No arguments, select all columns\n     * .query(\"select\",['username']) // only get the username column\n     * .query(\"select\",[\"username\",\"balance\"]) //Get two columns, username and balance.\n     * .query(\"select\",[\"count(*)\"]) //Get the length of records in the database\n     * ```\n     *\n     * ### Upsert\n     *\n     * Upsert is used to add or modify data in the database.\n     * If the primary key rows are null or undefined, the data will always be added in a new row. Otherwise, you might be updating existing rows.\n     * The second argument of the query with upserts is always an Object of the data to upsert.\n     *\n     * Examples:\n     * ```ts\n     * .query(\"upsert\",{id:1, username:\"Scott\"}) //If row ID 1 exists, set the username to scott, otherwise create a new row with this data.\n     * .query(\"upsert\",{username:\"Scott\"}) //Add a new row to the db with this username in the row.\n     * .query(\"upsert\",{balance:-35}).where([\"balance\",\"<\",0]) // If you use a WHERE statement this data will be applied to the rows found with the where statement.\n     * ```\n     *\n     * ### Delete\n     *\n     * Delete is used to remove data from the database.\n     * It works exactly like select, except it removes data instead of selecting it.  The second argument is an array of columns to clear.  If no second argument is passed, the entire row is deleted.\n     * If no where argument is passed, the entire table is dropped\n     *\n     * Examples:\n     * ```ts\n     * .query(\"delete\",['balance']) //Clear the contents of the balance column on ALL rows.\n     * .query(\"delete\",['comments']).where([\"accountType\",\"=\",\"spammer\"]) // If a where statment is passed you'll only clear the columns of the rows selected by the where statement.\n     * .query(\"delete\").where([\"balance\",\"<\",0]) // remove all rows with a balance less than zero\n     * .query(\"delete\") // Same as drop statement\n     * ```\n     *\n     * ### Drop\n     *\n     * Drop is used to completely clear the contents of a database.  There are no arguments.\n     *\n     * Drop Examples:\n     * ```ts\n     * .query(\"drop\")\n     * ```\n     *\n     * @param {(\"select\"|\"upsert\"|\"delete\"|\"drop\")} action\n     * @param {any} [args]\n     * @returns {NanoSQLInstance}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.query = function (action, args) {\n        /*let t = this;\n        t._queryPtr++;\n        if (t._queryPtr > t._queryPool.length - 1) {\n            t._queryPtr = 0;\n        }\n        const av = t._activeAV;\n        t._activeAV = undefined;\n        return t._queryPool[t._queryPtr].set(t.sTable, action.toLowerCase(), args, av);*/\n        var t = this;\n        var av = t._activeAV;\n        t._activeAV = undefined;\n        return new std_query_1._NanoSQLQuery(this, this.sTable, action, args, av);\n    };\n    NanoSQLInstance.prototype.onConnected = function (callback) {\n        if (this.isConnected) {\n            callback();\n        }\n        else {\n            this._onConnectedCallBacks.push(callback);\n        }\n    };\n    /**\n     * Trigger a database event\n     *\n     * @param {DatabaseEvent} eventData\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.triggerEvent = function (eventData) {\n        var t = this;\n        if (t._hasEvents[\"*\"] || t._hasEvents[eventData.table]) {\n            if (eventData.table === \"*\")\n                return this;\n            lie_ts_1.setFast(function () {\n                var c;\n                eventData.types.forEach(function (type) {\n                    // trigger wildcard\n                    t._callbacks[\"*\"].trigger(type, eventData, t);\n                    t._callbacks[\"*\"].trigger(\"*\", eventData, t);\n                    // trigger specific table\n                    if (eventData.table && t._callbacks[eventData.table]) {\n                        t._callbacks[eventData.table].trigger(type, eventData, t);\n                    }\n                });\n            });\n        }\n        return t;\n    };\n    /**\n     * Returns a default object for the current table's data model, useful for forms.\n     *\n     * The optional argument lets you pass in an object to over write the data model's defaults as desired.\n     *\n     * Examples:\n     *\n     * ```ts\n     * console.log(NanoSQL(\"users\").default()) <= {username:\"none\", id:undefined, age: 0}\n     * console.log(NanoSQL(\"users\").default({username:\"defalt\"})) <= {username:\"default\", id:undefined, age: 0}\n     * ```\n     *\n     * DO NOT use this inside upsert commands like `.query(\"upsert\",NanoSQL(\"users\").defalt({userObj}))..`.\n     * The database defaults are already applied through the upsert path, you'll be doing double work.\n     *\n     * Only use this to pull default values into a form in your UI or similar situation.\n     *\n     * @param {*} [replaceObj]\n     * @returns {{[key: string]: any}}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.default = function (replaceObj) {\n        var newObj = {};\n        var t = this;\n        if (Array.isArray(t.sTable))\n            return {};\n        t.dataModels[t.sTable].forEach(function (m) {\n            // set key to object argument or the default value in the data model\n            newObj[m.key] = (replaceObj && replaceObj[m.key]) ? replaceObj[m.key] : m.default;\n            // Generate default value from type, eg int = 0, string = \"\"\n            if (newObj[m.key] === undefined) {\n                newObj[m.key] = utilities_1.cast(m.type, null);\n            }\n        });\n        return newObj;\n    };\n    /**\n     * Get the raw contents of the database, provides all tables.\n     *\n     * Optionally pass in the tables to export.  If no tables are provided then all tables will be dumped.\n     *\n     * @returns\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.rawDump = function (tables) {\n        var _this = this;\n        return new Promise(function (res, rej) {\n            var result = {};\n            utilities_1.fastCHAIN(_this.plugins, function (plugin, i, next) {\n                if (plugin.dumpTables) {\n                    plugin.dumpTables(tables).then(function (tables) {\n                        result = __assign({}, result, tables);\n                        next(result);\n                    });\n                }\n                else {\n                    next();\n                }\n            }).then(function () {\n                res(result);\n            });\n        });\n    };\n    /**\n     * Import table data directly into the datatabase.\n     * Signifincatly faster than .loadJS but doesn't do type checking, indexing or anything else fancy.\n     *\n     * @param {{[table: string]: DBRow[]}} tables\n     * @returns\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.rawImport = function (tables, onProgress) {\n        var _this = this;\n        return new Promise(function (res, rej) {\n            utilities_1.fastCHAIN(_this.plugins, function (plugin, i, next) {\n                if (plugin.importTables) {\n                    plugin.importTables(tables, onProgress || (function (c) { })).then(next);\n                }\n                else {\n                    next();\n                }\n            }).then(function () {\n                res();\n            });\n        });\n    };\n    /**\n     * Request disconnect from all databases.\n     *\n     * @returns\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.disconnect = function () {\n        return utilities_1.fastCHAIN(this.plugins, function (plugin, i, next) {\n            if (plugin.willDisconnect) {\n                plugin.willDisconnect(next);\n            }\n            else {\n                next();\n            }\n        });\n    };\n    /**\n     * Executes a transaction against the database, batching all the queries together.\n     *\n     * @param {((\n     *         db: (table?: string) => {\n     *             query: (action: \"select\"|\"upsert\"|\"delete\"|\"drop\"|\"show tables\"|\"describe\", args?: any) => _NanoSQLTransactionQuery;\n     *             updateORM: (action: \"add\"|\"delete\"|\"drop\"|\"set\", column?: string, relationIDs?: any[]) => _NanoSQLTransactionORMQuery|undefined;\n     *         }, complete: () => void) => void)} initTransaction\n     * @returns {Promise<any>}\n     *\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.doTransaction = function (initTransaction) {\n        var _this = this;\n        var t = this;\n        var queries = [];\n        var transactionID = utilities_1.random16Bits().toString(16);\n        return new Promise(function (resolve, reject) {\n            if (!t.plugins.length) {\n                reject(\"nSQL: Nothing to do, no plugins!\");\n                return;\n            }\n            var run = function () {\n                utilities_1.fastCHAIN(t.plugins, function (p, i, nextP) {\n                    if (p.transactionBegin) {\n                        p.transactionBegin(transactionID, nextP);\n                    }\n                    else {\n                        nextP();\n                    }\n                }).then(function () {\n                    if (Array.isArray(t.sTable))\n                        return;\n                    initTransaction(function (table) {\n                        var ta = table || t.sTable;\n                        return {\n                            query: function (action, args) {\n                                return new transaction_1._NanoSQLTransactionQuery(action, args, ta, queries, transactionID);\n                            }\n                        };\n                    }, function () {\n                        var tables = [];\n                        utilities_1.fastCHAIN(queries, function (quer, i, nextQuery) {\n                            tables.push(quer.table);\n                            t.query(quer.action, quer.actionArgs).manualExec(__assign({}, quer, { table: quer.table, transaction: true, queryID: transactionID })).then(nextQuery);\n                        }).then(function (results) {\n                            utilities_1.fastCHAIN(_this.plugins, function (p, i, nextP) {\n                                if (p.transactionEnd) {\n                                    p.transactionEnd(transactionID, nextP);\n                                }\n                                else {\n                                    nextP();\n                                }\n                            }).then(function () {\n                                tables.filter(function (val, idx, self) {\n                                    return self.indexOf(val) === idx;\n                                }).forEach(function (table) {\n                                    if (table.indexOf(\"_\") !== 0) {\n                                        t.triggerEvent({\n                                            query: queries[0],\n                                            table: table,\n                                            time: new Date().getTime(),\n                                            result: results,\n                                            types: [\"transaction\"],\n                                            actionOrView: \"\",\n                                            notes: [],\n                                            transactionID: transactionID,\n                                            affectedRowPKS: [],\n                                            affectedRows: []\n                                        });\n                                    }\n                                });\n                                resolve(results);\n                            });\n                        });\n                    });\n                });\n            };\n            if (_this.isConnected) {\n                run();\n            }\n            else {\n                _this.onConnected(run);\n            }\n        });\n    };\n    /**\n     * Configure the database driver, must be called before the connect() method.\n     *\n     * @param {any} args\n     * @returns {NanoSQLInstance}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.config = function (args) {\n        this._config = args;\n        return this;\n    };\n    /**\n     * Init obvserable query.\n     *\n     * Usage:\n     * ```ts\n     * nSQL()\n     * .observable(() => nSQL(\"message\").query(\"select\").emit())\n     * .filter((rows, idx) => rows.length > 0)\n     * .subscribe((rows, event) => {\n     *\n     * });\n     *\n     * ```\n     *\n     * @template T\n     * @param {((ev?: DatabaseEvent) => IdbQueryExec|undefined)} getQuery\n     * @param {string[]} [tablesToListen]\n     * @returns {Observer<T>}\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.observable = function (getQuery, tablesToListen) {\n        return new observable_1.Observer(this, getQuery, tablesToListen || []);\n    };\n    /**\n     * Perform a custom action supported by the database driver.\n     *\n     * @param {...Array<any>} args\n     * @returns {*}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.extend = function () {\n        var _this = this;\n        var args = [];\n        for (var _i = 0; _i < arguments.length; _i++) {\n            args[_i] = arguments[_i];\n        }\n        var t = this;\n        return new Promise(function (res, rej) {\n            var run = function () {\n                if (t.plugins.length) { // Query Mode\n                    var newArgs_1 = args;\n                    var result_1 = [];\n                    utilities_1.fastCHAIN(t.plugins, function (p, i, nextP) {\n                        if (p.extend) {\n                            p.extend(function (nArgs, newResult) {\n                                newArgs_1 = nArgs;\n                                result_1 = newResult;\n                                nextP();\n                            }, newArgs_1, result_1);\n                        }\n                        else {\n                            nextP();\n                        }\n                    }).then(function () {\n                        res(result_1);\n                    });\n                }\n                else {\n                    rej(\"No plugins!\");\n                }\n            };\n            if (args[0] === \"beforeConn\") {\n                args.shift();\n                run();\n                return;\n            }\n            if (_this.isConnected) {\n                run();\n            }\n            else {\n                _this.onConnected(run);\n            }\n        });\n    };\n    /**\n     * Load JSON directly into the DB.\n     * JSON must be an array of maps, like this:\n     * ```ts\n     * [\n     *  {\"name\":\"billy\",\"age\":20},\n     *  {\"name\":\"johnny\":\"age\":30}\n     * ]\n     * ```\n     *\n     * Rows must align with the data model.  Row data that isn't in the data model will be ignored.\n     *\n     * @param {string} table\n     * @param {Array<Object>} rows\n     * @returns {Promise<Array<Object>>}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.loadJS = function (table, rows, useTransaction, onProgress) {\n        var _this = this;\n        var t = this;\n        if (useTransaction) {\n            return t.doTransaction(function (db, complete) {\n                rows.forEach(function (row) {\n                    db(table).query(\"upsert\", row).exec();\n                });\n                complete();\n            });\n        }\n        else {\n            return new Promise(function (res, rej) {\n                utilities_1.fastCHAIN(rows, function (row, i, nextRow) {\n                    if (onProgress)\n                        onProgress(Math.round(((i + 1) / rows.length) * 10000) / 100);\n                    _this.query(\"upsert\", row).manualExec({ table: table }).then(nextRow);\n                }).then(function (rows) {\n                    res(rows.map(function (r) { return r.shift(); }));\n                });\n            });\n        }\n    };\n    /**\n     * Convert a JSON array of objects to a CSV.\n     *\n     * @param {any[]} json\n     * @param {boolean} [printHeaders]\n     * @param {string[]} [useHeaders]\n     * @returns {string}\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.JSONtoCSV = function (json, printHeaders, useHeaders) {\n        var csv = [];\n        if (!json.length) {\n            return \"\";\n        }\n        var columnHeaders = [];\n        if (useHeaders) {\n            // use provided headers (much faster)\n            columnHeaders = useHeaders;\n        }\n        else {\n            // auto detect headers\n            json.forEach(function (json) {\n                columnHeaders = Object.keys(json).concat(columnHeaders);\n            });\n            columnHeaders = columnHeaders.filter(function (v, i, s) { return s.indexOf(v) === i; });\n        }\n        if (printHeaders) {\n            csv.push(columnHeaders.join(\",\"));\n        }\n        json.forEach(function (row) {\n            csv.push(columnHeaders.map(function (k) {\n                if (row[k] === null || row[k] === undefined) {\n                    return \"\";\n                }\n                if (typeof row[k] === \"string\") {\n                    // tslint:disable-next-line\n                    return \"\\\"\" + (row[k]).replace(/\\\"/g, '\\\"\\\"') + \"\\\"\";\n                }\n                if (typeof row[k] === \"boolean\") {\n                    return row[k] === true ? \"true\" : \"false\";\n                }\n                // tslint:disable-next-line\n                return typeof row[k] === \"object\" ? \"\\\"\" + JSON.stringify(row[k]).replace(/\\\"/g, '\\\"\\\"') + \"\\\"\" : row[k];\n            }).join(\",\"));\n        });\n        return csv.join(\"\\r\\n\");\n    };\n    NanoSQLInstance.prototype.csvToArray = function (text) {\n        // tslint:disable-next-line\n        var p = '', row = [''], ret = [row], i = 0, r = 0, s = !0, l;\n        for (var _i = 0, text_1 = text; _i < text_1.length; _i++) {\n            l = text_1[_i];\n            // tslint:disable-next-line\n            if ('\"' === l) {\n                if (s && l === p)\n                    row[i] += l;\n                s = !s;\n                // tslint:disable-next-line\n            }\n            else if (',' === l && s)\n                l = row[++i] = '';\n            // tslint:disable-next-line\n            else if ('\\n' === l && s) {\n                // tslint:disable-next-line\n                if ('\\r' === p)\n                    row[i] = row[i].slice(0, -1);\n                // tslint:disable-next-line\n                row = ret[++r] = [l = ''];\n                i = 0;\n            }\n            else\n                row[i] += l;\n            p = l;\n        }\n        return ret[0];\n    };\n    /**\n     * Convert a CSV to array of JSON objects\n     *\n     * @param {string} csv\n     * @param {(row: any) => any} [rowMap]\n     * @returns {*}\n     * @memberof NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.CSVtoJSON = function (csv, rowMap) {\n        var _this = this;\n        var t = this;\n        var fields = [];\n        return csv.split(/\\r?\\n|\\r|\\t/gm).map(function (v, k) {\n            if (k === 0) {\n                fields = v.split(\",\");\n                return undefined;\n            }\n            else {\n                var row = _this.csvToArray(v);\n                if (!row)\n                    return undefined;\n                row = row.map(function (r) { return r.trim(); });\n                var i = fields.length;\n                var record = {};\n                while (i--) {\n                    if (row[i]) {\n                        if (row[i] === \"true\" || row[i] === \"false\") {\n                            record[fields[i]] = row[i] === \"true\";\n                        }\n                        else if (row[i].indexOf(\"{\") === 0 || row[i].indexOf(\"[\") === 0) {\n                            // tslint:disable-next-line\n                            try {\n                                record[fields[i]] = JSON.parse(row[i]);\n                            }\n                            catch (e) {\n                                record[fields[i]] = row[i];\n                            }\n                            // tslint:disable-next-line\n                        }\n                        else if (row[i].indexOf('\"') === 0) {\n                            record[fields[i]] = row[i].slice(1, row[i].length - 1).replace(/\\\"\\\"/gmi, \"\\\"\");\n                        }\n                        else {\n                            record[fields[i]] = row[i];\n                        }\n                    }\n                }\n                if (rowMap) {\n                    return rowMap(record);\n                }\n                return record;\n            }\n        }).filter(function (r) { return r; });\n    };\n    /**\n     * Load a CSV file into the DB.  Headers must exist and will be used to identify what columns to attach the data to.\n     *\n     * This function performs a bunch of upserts, so expect appropriate behavior based on the primary key.\n     *\n     * Rows must align with the data model.  Row data that isn't in the data model will be ignored.\n     *\n     * @param {string} csv\n     * @returns {(Promise<Array<Object>>)}\n     *\n     * @memberOf NanoSQLInstance\n     */\n    NanoSQLInstance.prototype.loadCSV = function (table, csv, useTransaction, rowMap, onProgress) {\n        var _this = this;\n        var t = this;\n        var rowData = this.CSVtoJSON(csv, rowMap);\n        if (useTransaction) {\n            return t.doTransaction(function (db, complete) {\n                rowData.forEach(function (row) {\n                    db(table).query(\"upsert\", row).exec();\n                });\n                complete();\n            });\n        }\n        else {\n            return new Promise(function (res, rej) {\n                utilities_1.fastCHAIN(rowData, function (row, i, nextRow) {\n                    if (onProgress)\n                        onProgress(Math.round(((i + 1) / rowData.length) * 10000) / 100);\n                    _this.query(\"upsert\", row).manualExec({ table: table }).then(nextRow);\n                }).then(function (rows) {\n                    res(rows.map(function (r) { return r.shift(); }));\n                });\n            });\n        }\n    };\n    NanoSQLInstance.earthRadius = 6371;\n    return NanoSQLInstance;\n}());\nexports.NanoSQLInstance = NanoSQLInstance;\nvar wordLevenshtienCache = {};\nNanoSQLInstance.whereFunctions = {\n    levenshtein: function (row, isJoin, word, column) {\n        var val = utilities_1.objQuery(column, row, isJoin) || \"\";\n        var key = val + \"::\" + word;\n        if (!wordLevenshtienCache[key]) {\n            wordLevenshtienCache[key] = levenshtein(val, word);\n        }\n        return wordLevenshtienCache[key];\n    },\n    arrayObjSrch: function (row, isJoin, arrayKey, objCompare, compareKey) {\n        var arr = utilities_1.objQuery(arrayKey, row, isJoin);\n        if (!Array.isArray(arr))\n            return undefined;\n        if (!arr.length)\n            return undefined;\n        var matchingObj;\n        var objData = objCompare.split(\"=\");\n        arr.forEach(function (obj) {\n            var key = utilities_1.objQuery(objData[0], obj);\n            key = isNaN(key) ? key : parseFloat(key);\n            objData[1] = isNaN(objData[1]) ? objData[1] : parseFloat(objData[1]);\n            if (key === objData[1]) {\n                matchingObj = obj;\n            }\n        });\n        if (matchingObj === undefined)\n            return undefined;\n        return utilities_1.objQuery(compareKey, matchingObj);\n    },\n    crow: function (row, isJoin, lat, lon, latColumn, lonColumn) {\n        var latCol = latColumn || \"lat\";\n        var lonCol = lonColumn || \"lon\";\n        var latVal = utilities_1.objQuery(latCol, row, isJoin);\n        var lonVal = utilities_1.objQuery(lonCol, row, isJoin);\n        return utilities_1.crowDistance(latVal, lonVal, lat, lon, NanoSQLInstance.earthRadius);\n    },\n    sum: function (row, isJoin) {\n        var columns = [];\n        for (var _i = 2; _i < arguments.length; _i++) {\n            columns[_i - 2] = arguments[_i];\n        }\n        return columns.reduce(function (prev, cur) {\n            var val = utilities_1.objQuery(cur, row, isJoin) || 0;\n            if (Array.isArray(val)) {\n                return prev + val.reduce(function (p, c) { return p + parseFloat(c || 0); }, 0);\n            }\n            return prev + parseFloat(val);\n        }, 0);\n    },\n    avg: function (row, isJoin) {\n        var columns = [];\n        for (var _i = 2; _i < arguments.length; _i++) {\n            columns[_i - 2] = arguments[_i];\n        }\n        var numRecords = 0;\n        var total = columns.reduce(function (prev, cur) {\n            var val = utilities_1.objQuery(cur, row, isJoin) || 0;\n            if (Array.isArray(val)) {\n                numRecords += val.length;\n                return prev + val.reduce(function (p, c) { return p + parseFloat(c || 0); }, 0);\n            }\n            numRecords++;\n            return prev + parseFloat(val);\n        }, 0);\n        return total / numRecords;\n    }\n};\nNanoSQLInstance.functions = {\n    COUNT: {\n        type: \"A\",\n        call: function (rows, complete, isJoin, column) {\n            if (column && column !== \"*\") {\n                complete(rows.filter(function (r) { return utilities_1.objQuery(column, r, isJoin); }).length);\n            }\n            else {\n                complete(rows.length);\n            }\n        }\n    },\n    MAX: {\n        type: \"A\",\n        call: function (rows, complete, isJoin, column) {\n            if (rows.length) {\n                var max_1 = utilities_1.objQuery(column, rows[0]) || 0;\n                var maxRow_1 = rows[0];\n                rows.forEach(function (r) {\n                    var v = utilities_1.objQuery(column, r, isJoin);\n                    if (utilities_1.objQuery(column, r) > max_1) {\n                        maxRow_1 = r;\n                        max_1 = utilities_1.objQuery(column, r, isJoin);\n                    }\n                });\n                complete(max_1, maxRow_1);\n            }\n            else {\n                complete(0);\n            }\n        }\n    },\n    MIN: {\n        type: \"A\",\n        call: function (rows, complete, isJoin, column) {\n            if (rows.length) {\n                var min_1 = utilities_1.objQuery(column, rows[0], isJoin) || 0;\n                var minRow_1 = rows[0];\n                rows.forEach(function (r) {\n                    var v = utilities_1.objQuery(column, r, isJoin);\n                    if (v < min_1) {\n                        min_1 = v;\n                        minRow_1 = r;\n                    }\n                });\n                complete(min_1, minRow_1);\n            }\n            else {\n                complete(0);\n            }\n        }\n    },\n    AVG: {\n        type: \"A\",\n        call: function (rows, complete, isJoin, column) {\n            complete(rows.reduce(function (prev, cur) { return prev + (utilities_1.objQuery(column, cur, isJoin) || 0); }, 0) / rows.length);\n        }\n    },\n    SUM: {\n        type: \"A\",\n        call: function (rows, complete, isJoin, column) {\n            complete(rows.reduce(function (prev, cur) { return prev + (utilities_1.objQuery(column, cur, isJoin) || 0); }, 0));\n        }\n    },\n    LOWER: {\n        type: \"S\",\n        call: function (rows, complete, isJoin, column) {\n            complete(rows.map(function (r) {\n                return String(utilities_1.objQuery(column, r, isJoin)).toLowerCase();\n            }));\n        }\n    },\n    UPPER: {\n        type: \"S\",\n        call: function (rows, complete, isJoin, column) {\n            complete(rows.map(function (r) {\n                return String(utilities_1.objQuery(column, r, isJoin)).toUpperCase();\n            }));\n        }\n    },\n    CAST: {\n        type: \"S\",\n        call: function (rows, complete, isJoin, column, type) {\n            complete(rows.map(function (r) {\n                return utilities_1.cast(type, utilities_1.objQuery(column, r, isJoin));\n            }));\n        }\n    },\n    ABS: {\n        type: \"S\",\n        call: function (rows, complete, isJoin, column) {\n            complete(rows.map(function (r) {\n                return Math.abs(utilities_1.objQuery(column, r, isJoin));\n            }));\n        }\n    },\n    CEIL: {\n        type: \"S\",\n        call: function (rows, complete, isJoin, column) {\n            complete(rows.map(function (r) {\n                return Math.ceil(utilities_1.objQuery(column, r, isJoin));\n            }));\n        }\n    },\n    POW: {\n        type: \"S\",\n        call: function (rows, complete, isJoin, column, power) {\n            complete(rows.map(function (r) {\n                return Math.pow(utilities_1.objQuery(column, r, isJoin), parseInt(power));\n            }));\n        }\n    },\n    ROUND: {\n        type: \"S\",\n        call: function (rows, complete, isJoin, column) {\n            complete(rows.map(function (r) {\n                return Math.round(utilities_1.objQuery(column, r, isJoin));\n            }));\n        }\n    },\n    SQRT: {\n        type: \"S\",\n        call: function (rows, complete, isJoin, column) {\n            complete(rows.map(function (r) {\n                return Math.sqrt(utilities_1.objQuery(column, r, isJoin));\n            }));\n        }\n    }\n};\n/**\n * @internal\n */\nvar _NanoSQLStatic = new NanoSQLInstance();\nexports.nSQL = function (setTablePointer) {\n    return _NanoSQLStatic.table(setTablePointer);\n};\nif (typeof window !== \"undefined\") {\n    window[\"nano-sql\"] = {\n        nSQL: exports.nSQL,\n        NanoSQLInstance: NanoSQLInstance\n    };\n}\n"]}