1 line
14 KiB
Plaintext
1 line
14 KiB
Plaintext
{"version":3,"sources":["webpack://pawsqlite/./src/adapter_wrapper.mjs","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","webpack://pawsqlite/webpack/bootstrap","webpack://pawsqlite/webpack/runtime/define property getters","webpack://pawsqlite/webpack/runtime/hasOwnProperty shorthand","webpack://pawsqlite/webpack/runtime/make namespace object","webpack://pawsqlite/./src/pawsqlite_cjs.mjs"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAuD;;;AAGhD;AACP;;AAEA;AACA;AACA,gBAAgB,gEAAc,uCAAuC,OAAO;AAC5E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,gEAAc;AAC9B;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAS;AACT,gBAAgB,qEAAmB;AACnC;AACA;AACA,KAAK;AACL;AACA;AACA,GAAG;;AAEH;AACA,C;;;;;;;;;;;;;;;ACtC+D;;;AAGxD;AACP;AACA;AACA;AACA;AACA;;AAEA,kCAAkC,wEAAkB;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;;AAEO;AACP;AACA;AACA,G;AACA;;AAEO;AACP;AACA;;AAEA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;;;;;;;;AChB0C;AACU;AACG;AACV;;AAEU;;;AAGvD;;AAEO;AACP,2CAA2C;AAC3C;;AAEA,iBAAiB,mDAAQ;AACzB;AACA;AACA,GAAG;AACH,uCAAuC;AACvC;;AAEA;AACA,GAAG;AACH;AACA;AACA,gBAAgB,gEAAc;AAC9B;;AAEA,oBAAoB,iEAAW;;AAE/B;AACA,gBAAgB,gEAAc,8BAA8B,eAAe;AAC3E;AACA;;AAEA,IAAI,6CAAG,wBAAwB,eAAe;;AAE9C;AACA,GAAG;AACH,SAAS,iDAAW;AACpB;;;;AAIA;AACA;;AAEA;AACA,cAAc,gEAAc,qBAAqB,YAAY;AAC7D;;AAEA;AACA,C;;;;;;;;;;;;;;ACpDO;AACP;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;;;;ACXuD;;;AAGhD;AACP;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;;;;;AClBsC;AACiB;;;AAGhD;AACP;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,gBAAgB,gEAAc;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,gEAAc;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,gEAAc;AAC9B;AACA;;AAEA;AACA;;AAEA,eAAe,+CAAM;AACrB;;AAEA;AACA;AACA;;AAEA;AACA;AACA,gBAAgB,gEAAc;AAC9B;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA,eAAe,+CAAM;AACrB;AACA,C;;;;;;;;;;;;;;;ACzIgD;;AAEzC;AACP;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,eAAe,yDAAW;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;;;;;;UCtDA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCrBA;WACA;WACA;WACA;WACA,wCAAwC,yCAAyC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,sDAAsD,kBAAkB;WACxE;WACA,+CAA+C,cAAc;WAC7D,E;;;;;;;;;;;;;;;;ACN4C;AACW;;AAEvD,iEAAe;AACf,SAAS,gEAAc;AACvB,CAAC,EAAE,qDAAS,CAAC,E","file":"pawsqlite.js","sourcesContent":["import { PawSQLiteError } from \"./pawsqlite_error.mjs\";\n\n\nexport function wrapAdapter(adapter) {\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}","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 { wrapAdapter } from \"./adapter_wrapper.mjs\";\nimport { PawSQLiteError } from \"./pawsqlite_error.mjs\";\nimport { enableDebug, log } from \"./log.mjs\";\n\nexport { PawSQLiteError } from \"./pawsqlite_error.mjs\";\n\n\nconst adapters = [];\n\nexport const PawSQLite = {\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 if (!adapter) {\n throw new PawSQLiteError(\"Invalid adapter\");\n }\n\n const wrapped = wrapAdapter(adapter);\n\n if (getAdapter(wrapped.name, true)) {\n throw new PawSQLiteError(`An adapter with the name: ${ wrapped.name } ` +\n `Already exists`);\n }\n\n log(`Registered adapter: ${ wrapped.name }`);\n\n adapters.push(wrapped);\n },\n debug: enableDebug\n};\n\n\n\nfunction getAdapter(adapterName, silent=false) {\n const adapter = adapters.find((a) => a.name === adapterName);\n\n if (!(silent || 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}","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { PawSQLite } from \"./pawsqlite.mjs\";\nimport { PawSQLiteError } from \"./pawsqlite_error.mjs\";\n\nexport default Object.assign({\n Error: PawSQLiteError\n}, PawSQLite);"],"sourceRoot":""} |