{"version":3,"sources":["webpack://pawsqlite/webpack/bootstrap","webpack://pawsqlite/./src/database.mjs","webpack://pawsqlite/./src/log.mjs","webpack://pawsqlite/./src/pawsqlite.mjs","webpack://pawsqlite/./src/pawsqlite_error.mjs","webpack://pawsqlite/./src/result.mjs","webpack://pawsqlite/./src/transaction.mjs","webpack://pawsqlite/./src/transaction_manager.mjs"],"names":[],"mappings":";;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;AClFA;AAAA;AAAA;AAA+D;;;AAGxD;AACP;AACA;AACA;AACA;AACA;;AAEA,kCAAkC,2EAAkB;AACpD;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;;AAGA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;AC/DA;AAAA;AAAA;AAAA;;AAEO;AACP;AACA;AACA,G;AACA;;AAEO;AACP;AACA;;AAEA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;AChBA;AAAA;AAAA;AAAA;AAA0C;AACa;AACf;;;AAGxC;;;AAGe;AACf,2CAA2C;AAC3C;;AAEA,iBAAiB,sDAAQ;AACzB;AACA;AACA,GAAG;AACH,uCAAuC;AACvC;;AAEA;AACA,GAAG;AACH;AACA;AACA,GAAG;AACH,SAAS,oDAAW;AACpB,SAAS,mEAAc;AACvB,CAAC,EAAC;;;AAGF;AACA;;AAEA;AACA;AACA,gBAAgB,mEAAc,uCAAuC,OAAO;AAC5E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,mEAAc;AAC9B;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAS;AACT,gBAAgB,mEAAc;AAC9B;AACA;AACA,KAAK;AACL;AACA;AACA,GAAG;;AAEH;AACA;;;AAGA;AACA;;AAEA;AACA,cAAc,mEAAc,qBAAqB,YAAY;AAC7D;;AAEA;AACA,C;;;;;;;;;;;;AC3EA;AAAA;AAAO;AACP;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;ACXA;AAAA;AAAA;AAAuD;;;AAGhD;AACP;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;AClBA;AAAA;AAAA;AAAA;AAAsC;AACiB;;;AAGhD;AACP;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,gBAAgB,mEAAc;AAC9B;;AAEA;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,mEAAc;AAC9B;AACA;;AAEA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,gBAAgB,mEAAc;AAC9B;AACA;;AAEA;AACA;;AAEA,eAAe,kDAAM;AACrB;;AAEA;AACA;AACA;;AAEA;AACA;AACA,gBAAgB,mEAAc;AAC9B;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA,eAAe,kDAAM;AACrB;AACA,C;;;;;;;;;;;;ACzIA;AAAA;AAAA;AAAgD;;AAEzC;AACP;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,eAAe,4DAAW;AAC1B;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL,sBAAsB,iCAAiC;;AAEvD;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,C","file":"pawsqlite.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/pawsqlite.mjs\");\n","import { TransactionManager } from \"./transaction_manager.mjs\";\n\n\nexport class Database {\n constructor(dbName, adapter) {\n this.dbName = dbName;\n this.adapter = adapter;\n this.version = null;\n this.path = null;\n\n this.transactionManager = new TransactionManager(dbName, this.adapter);\n }\n\n async open() {\n let response = await this.adapter.open(this.dbName);\n\n if (response) {\n if (response.hasOwnProperty('version')) {\n this.version = response.version;\n }\n if (response.hasOwnProperty('path')) {\n this.path = response.path;\n }\n }\n\n // Allow chaining\n return this;\n }\n\n close() {\n return this.adapter.close(this.dbName);\n }\n\n transaction() {\n return this.transactionManager.transaction();\n }\n\n\n async autoTransaction(cb, inheritTx) {\n let tx = inheritTx || this.transaction();\n let result;\n\n try {\n result = await cb(tx);\n } catch (e) {\n if (!inheritTx) {\n await tx.rollback();\n }\n throw e;\n }\n\n if (!inheritTx) {\n await tx.commit();\n }\n\n return result;\n }\n\n\n // Helper method to start a transaction and execute a single SQL statement\n sql(sql, ...args) {\n return this.autoTransaction((tx) => tx.sql(sql, ...args));\n }\n}","let DEBUG = false;\n\nexport function log(...args) {\n if (DEBUG) {\n console.log(...args);\n } \n}\n\nexport function enableDebug(active) {\n DEBUG = !!active;\n log(\"PawSQLite: debugging \" + (DEBUG ? \"enabled\" : \"disabled\"));\n\n if (DEBUG) {\n log(\"You might also want to enable debugging for the adapter that you \" +\n \"are using\");\n }\n}","import { Database } from \"./database.mjs\";\nimport { PawSQLiteError } from \"./pawsqlite_error.mjs\";\nimport { enableDebug } from \"./log.mjs\";\n\n\nconst adapters = [];\n\n\nexport default {\n open: async function(dbName, options = {}) {\n const adapter = getAdapter(options.adapter);\n\n let db = new Database(dbName, adapter);\n await db.open();\n return db;\n },\n delete: function(dbName, options = {}) {\n const adapter = getAdapter(options.adapter);\n\n return adapter.delete(dbName);\n },\n registerAdapter: function(adapter) {\n adapters.push(wrapAdapter(adapter));\n },\n debug: enableDebug,\n Error: PawSQLiteError\n};\n\n\nfunction wrapAdapter() {\n const wrapped = {};\n\n [\"name\", \"open\", \"close\", \"delete\", \"sql\"].forEach((prop) => {\n if (!(prop in adapter)) {\n throw new PawSQLiteError(`Invalid adapter: missing property: ${ prop }`);\n }\n\n if (\n prop === \"name\" && !(\n typeof adapter[prop] === \"string\" ||\n adapter[prop] instanceof String\n ) ||\n prop !== \"name\" && (\n typeof adapter[prop] !== \"function\"\n )\n ) {\n throw new PawSQLiteError(\"Invalid adapter: invalid type for property: \" +\n prop);\n }\n\n if (typeof adapter[prop] === \"function\") {\n wrapped[prop] = async (...args) => {\n try {\n return await adapter[prop](...args);\n } catch (err) {\n throw PawSQLiteError.from(err);\n }\n };\n } else {\n wrapped[prop] = adapter[prop];\n }\n });\n\n return wrapped;\n}\n\n\nfunction getAdapter(adapterName) {\n const adapter = adapters.find((a) => a.name === adapterName);\n\n if (!adapter) {\n throw new PawSQLiteError(`Unknown Adapter: ${adapterName}`);\n }\n\n return adapter;\n}","export class PawSQLiteError extends Error {\n static from(err) {\n const p_err = new PawSQLiteError(err.toString());\n p_err.cause = err;\n return p_err;\n }\n\n constructor(message) {\n super(message);\n this.name = \"PawSQLiteError\";\n }\n}","import { PawSQLiteError } from \"./pawsqlite_error.mjs\";\n\n\nexport class Result extends Array {\n constructor(result) {\n if (result.hasOwnProperty(\"rows\")) {\n super(...result.rows);\n } else {\n super();\n }\n\n if (result.hasOwnProperty(\"insertId\")) {\n this.insertId = result.insertId;\n }\n if (result.hasOwnProperty(\"rowsAffected\")) {\n this.rowsAffected = result.rowsAffected;\n }\n }\n}","import { Result } from \"./result.mjs\";\nimport { PawSQLiteError } from \"./pawsqlite_error.mjs\";\n\n\nexport class Transaction {\n constructor(dbName, adapter, enqueue, rollbackOnError=false) {\n this.dbName = dbName;\n this.adapter = adapter;\n this._rollbackOnError = rollbackOnError;\n\n this._enqueue = enqueue;\n this._completeCb = null;\n\n this._readyWait = null;\n this._ready = false;\n this._finalized = false;\n }\n\n async sql(sql, ...args) {\n if (this._finalized) {\n throw new PawSQLiteError(\"Transaction has already completed\");\n }\n\n if (!this._ready) {\n await this._waitUntilReady();\n }\n\n try {\n return await this._executeSQL(sql, ...args);\n } catch (e) {\n if (this._rollbackOnError) {\n await this.rollback();\n }\n throw e;\n }\n }\n\n // Allow for slightly more complex parameter substitution.\n // Instances of \"???\" will be replaced by the same number of comma-separated\n // question marks as items in the corresponding nested parateter array\n // eg. buildQuery(\"SELECT (???) FROM ?\", [[\"col1\", \"col2\"], \"table1\"])\n // would output: [\"SELECT (?, ?) FROM ?\", [\"col1\", \"col2\", \"table1\"]]\n buildQuery(sql, ...args) {\n const parts = sql.split(\"???\");\n const subParamLengths = args\n .filter(Array.isArray)\n .map((a) => a.length);\n if (parts.length !== subParamLengths.length + 1) {\n throw new PawSQLiteError(\"Unable to build query: sub-\" +\n \"paramters do not match sub-paramters in query\");\n }\n\n const newQuery = parts.reduce((p1, p2, i) => {\n const length = subParamLengths[i - 1];\n return p1 + new Array(length).fill(\"?\").join(\", \") + p2;\n });\n\n const flatParams = args.reduce((acc, v) => {\n if (Array.isArray(v)) {\n Array.prototype.push.apply(acc, v);\n } else {\n acc.push(v);\n }\n return acc;\n }, []);\n\n return [newQuery, ...flatParams];\n }\n\n commit() {\n return this._complete(\"COMMIT\");\n }\n\n rollback() {\n return this._complete(\"ROLLBACK\");\n }\n\n async _waitUntilReady() {\n if (!this._readyWait) {\n this._readyWait = (async () => {\n this._completeCb = await this._enqueue();\n await this._begin();\n this._ready = true;\n })();\n }\n \n await this._readyWait;\n }\n\n async _executeSQL(sql, ...args) {\n const reg = /^\\s*(BEGIN|END|COMMIT|ROLLBACK)(?:[^A-Z]|$)/i;\n const match = reg.exec(sql);\n if (match) {\n const statement = match[1].toUpperCase();\n throw new PawSQLiteError(\"Manually managing transactions is \" +\n \"forbidden. Found: \\\"\" + statement + \"\\\" statement.\");\n }\n\n const result = await this.adapter.sql(this.dbName,\n ...this.buildQuery(sql, ...args));\n\n return new Result(result);\n }\n\n async _begin() {\n const result = await this.adapter.sql(this.dbName, \"BEGIN\");\n }\n\n async _complete(sql) {\n if (this._finalized) {\n throw new PawSQLiteError(\"Transaction has already completed\");\n }\n this._finalized = true;\n\n if (!this._readyWait) {\n // Transaction was unused\n return;\n } else if (!this._ready) {\n await this._waitUntilReady();\n }\n\n let result;\n let error;\n try {\n result = await this.adapter.sql(this.dbName, sql);\n } catch (e) {\n error = e;\n }\n \n this._completeCb();\n \n if (error) {\n throw error;\n }\n\n return new Result(result);\n }\n}","import { Transaction } from \"./transaction.mjs\";\n\nexport class TransactionManager {\n constructor(dbName, adapter) {\n this.dbName = dbName;\n this.adapter = adapter;\n this._queue = [];\n this._inTransaction = false;\n }\n\n transaction() {\n return new Transaction(this.dbName, this.adapter,\n this.enqueue.bind(this));\n }\n\n enqueue() {\n let completeSignal;\n let transactionComplete = new Promise((r, _) => {\n completeSignal = r;\n });\n\n let readySignal;\n let dbReady = new Promise((r, _) => {\n readySignal = () => {\n r(completeSignal);\n };\n });\n\n this._queue.push({readySignal, transactionComplete});\n\n this._processQueue();\n return dbReady;\n }\n\n async _processQueue() {\n // We're already processing the queue\n if (this._inTransaction) {\n return;\n }\n\n while (true) {\n let item = this._queue.shift();\n if (!item) {\n return;\n }\n\n this._inTransaction = true;\n\n item.readySignal();\n await item.transactionComplete;\n\n this._inTransaction = false;\n }\n }\n}"],"sourceRoot":""}