PawSQLite-WebSQL-Adapter/cjs/pawsqlite-websql-adapter.js.map
2021-03-14 22:06:06 -07:00

1 line
11 KiB
Plaintext

{"version":3,"sources":["webpack://pawsqlite-websql-adapter/./src/database_wrapper.mjs","webpack://pawsqlite-websql-adapter/./src/log.mjs","webpack://pawsqlite-websql-adapter/./src/response_wrapper.mjs","webpack://pawsqlite-websql-adapter/./src/result_mapper.mjs","webpack://pawsqlite-websql-adapter/./src/transaction_manager.mjs","webpack://pawsqlite-websql-adapter/./src/websql_adapter_error.mjs","webpack://pawsqlite-websql-adapter/webpack/bootstrap","webpack://pawsqlite-websql-adapter/webpack/runtime/define property getters","webpack://pawsqlite-websql-adapter/webpack/runtime/hasOwnProperty shorthand","webpack://pawsqlite-websql-adapter/webpack/runtime/make namespace object","webpack://pawsqlite-websql-adapter/./src/websql_adapter.mjs"],"names":[],"mappings":";;;;;;;;;;;;;;;AAA+D;;;AAGxD;AACP;AACA;AACA;AACA,4BAA4B,wEAAkB;AAC9C;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,C;;;;;;;;;;;;;;;AC7BA;;AAEO;AACP;AACA;AACA,G;AACA;;AAEO;AACP;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;;;ACbO;AACP,oBAAoB;AACpB;AACA;AACA,GAAG;AACH;;;;;;;;;;;;;;;;;ACLO;AACP;AACA;AACA;AACA;;AAEA;AACA;AACA,GAAG;;AAEH;;AAEA;AACA;;AAEA,mBAAmB,gCAAgC;AACnD;AACA;AACA;;AAEA;AACA,C;;;;;;;;;;;;;;;;;ACrBgE;AAChB;AAChB;;;AAGhC;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,KAAK;AACL;AACA;;;AAGO;AACP;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,qBAAqB,yEAAkB;AACvC;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,OAAO;AACP,KAAK,oBAAoB,6DAAS;AAClC;;AAEA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA,6BAA6B,6DAAS;AACtC,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA,4DAA4D,6DAAS;AACrE,KAAK;AACL;;;AAGA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,WAAW;AACX;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA,YAAY,6CAAG,iBAAiB,gBAAgB,eAAe,iBAAiB;AAChF;AACA,SAAS;AACT;AACA;AACA;AACA;;AAEA;AACA;;;AAGA;AACA;AACA;AACA;AACA;;;AAGA;AACA;AACA;AACA,mBAAmB,yEAAkB;AACrC;AACA;AACA;AACA;AACA,gBAAgB,6DAAS;AACzB,OAAO;AACP,eAAe,8EAAuB;AACtC;AACA,OAAO;AACP,KAAK;AACL;;AAEA;AACA;AACA;AACA,C;;;;;;;;;;;;;;AC3JO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;;;;;;UCRA;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;;;;;;;;;;;;;;;;;;ACNgE;AACP;AACA;AACZ;;AAE7C;;AAEO;AACP;AACA;AACA;;AAEA;AACA,gCAAgC,kEAAe;AAC/C;;AAEA,WAAW,0EAAuB,EAAE,UAAU;AAC9C,GAAG;;AAEH;AACA;AACA,WAAW,0EAAuB;AAClC,GAAG;;AAEH;AACA,IAAI,6CAAG;;AAEP;AACA;AACA,gBAAgB,yEAAkB;AAClC;;AAEA;AACA,WAAW,0EAAuB;AAClC,GAAG;;AAEH;AACA,cAAc,yEAAkB;AAChC,GAAG;;AAEH,SAAS,iDAAW;AACpB","file":"pawsqlite-websql-adapter.js","sourcesContent":["import { TransactionManager } from \"./transaction_manager.mjs\";\n\n\nexport class DatabaseWrapper {\n constructor(dbName, version) {\n this.name = dbName;\n this.db = openDatabase(this.name, version, \"\", 5 * 1024 * 1024);\n this.transManager = new TransactionManager(this.db);\n }\n\n sql(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\n switch(statement) {\n case \"BEGIN\":\n return this.transManager.begin();\n case \"END\":\n case \"COMMIT\":\n return this.transManager.commit();\n case \"ROLLBACK\":\n return this.transManager.rollback();\n }\n } else {\n return this.transManager.sql(sql, args);\n }\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-WebSQL-Adapter: debugging \" + (\n DEBUG ? \"enabled\" : \"disabled\")\n );\n}","export const ResponseWrapper = {\n success: (obj = {}) => ({\n success: true,\n ...obj\n })\n};\n\n\n","export function mapResult(originalResult) {\n const newResult = {};\n if (!originalResult) {\n return newResult;\n }\n\n try {\n newResult.insertId = originalResult.insertId;\n } catch (e) {}\n\n newResult.rowsAffected = originalResult.rowsAffected;\n\n if (\"rows\" in originalResult) {\n newResult.rows = [];\n\n for (let i = 0; i < originalResult.rows.length; i++) {\n newResult.rows.push(originalResult.rows.item(i));\n }\n }\n\n return newResult;\n}","import { WebSQLAdapterError } from \"./websql_adapter_error.mjs\";\nimport { mapResult } from \"./result_mapper.mjs\";\nimport { log } from \"./log.mjs\";\n\n\nclass Task {\n constructor(job, startsTransaction=false, endsTransaction=false) {\n this._job = job;\n\n if (startsTransaction && endsTransaction) {\n throw new Error(\"Task cannot start and end a transaction.\");\n }\n\n this.startsTransaction = startsTransaction;\n this.endsTransaction = endsTransaction;\n\n this.result = new Promise ((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n\n run(tx) {\n return this._job(tx).then((result) => {\n this._resolve(result);\n return result;\n }, (e) => {\n this._reject(e);\n });\n }\n}\n\n\nexport class TransactionManager {\n constructor(db) {\n this.db = db;\n\n this._txCount = 0;\n this._tasks = [];\n this._processing = false;\n }\n\n begin() {\n return this._addTask(new Task((tx) => {\n return new Promise((resolve, reject) => {\n if (tx) {\n reject(new WebSQLAdapterError(\"BEGIN called with an active \" +\n \"transaction. This should not happen\"));\n return;\n }\n this.db.transaction((tx) => {\n resolve(tx);\n });\n });\n }, true)).then(() => mapResult());\n }\n\n sql(sql, args = []) {\n return this._addTask(new Task((tx) => {\n return this._executeSql(tx, sql, args);\n }));\n }\n\n commit() {\n return this._addTask(new Task((tx) => {\n return Promise.resolve(mapResult());\n }, false, true));\n }\n\n rollback() {\n // Hack to manually cause rollback:\n // Intentionally cause an error with rollbackOnError set to true\n return this._addTask(new Task((tx) => {\n return this._executeSql(tx, \"\", [], true).catch(() => mapResult());\n }, false, true));\n }\n\n\n async _process() {\n if (this._processing) {\n return;\n }\n this._processing = true;\n\n let tx = null;\n let keepaliveCount = 0;\n\n while (true) {\n const tasks = this._tasks;\n this._tasks = [];\n\n\n if (tasks.length) {\n const promises = [];\n\n for (const task of tasks) {\n const promise = task.run(tx);\n\n if (task.startsTransaction) {\n tx = await promise;\n this._txCount++;\n } else {\n if (task.endsTransaction) {\n tx = null;\n keepaliveCount = 0;\n }\n\n promises.push(promise);\n }\n }\n\n await Promise.all(promises);\n } else {\n if (tx) {\n await this._nop(tx);\n keepaliveCount++;\n if (keepaliveCount % 5000 === 0) {\n log(`Transaction: ${ this._txCount } Keepalive: #${ keepaliveCount }`);\n }\n } else {\n break;\n }\n }\n }\n\n this._processing = false;\n }\n\n\n _addTask(task) {\n this._tasks.push(task);\n this._process();\n return task.result;\n }\n\n\n _executeSql(tx, sql, sqlArgs = [], rollbackOnError = false) {\n return new Promise((resolve, reject) => {\n if (!tx) {\n reject(new WebSQLAdapterError(\"No transaction. This should not be \" +\n \" possible\"));\n return;\n }\n tx.executeSql(sql, sqlArgs, (tx, result) => {\n resolve(mapResult(result));\n }, (tx, e) => {\n reject(WebSQLAdapterError.from(e));\n return rollbackOnError;\n });\n });\n }\n\n _nop(tx) {\n return this._executeSql(tx, \"SELECT 1\");\n }\n}","export class WebSQLAdapterError extends Error {\n static from(e) {\n let message = \"\";\n if (e && e.message) {\n message = e.message;\n }\n return new WebSQLAdapterError(message);\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 { WebSQLAdapterError } from \"./websql_adapter_error.mjs\";\nimport { DatabaseWrapper } from \"./database_wrapper.mjs\";\nimport { ResponseWrapper } from \"./response_wrapper.mjs\";\nimport { enableDebug, log } from \"./log.mjs\";\n\nconst databases = new Map();\n\nexport const PawSQLiteWebSQLAdapter = {\n name: \"PawSQLiteWebSQLAdapter\",\n open: async (dbName) => {\n const version = \"1.0\";\n\n if (!databases.has(dbName)) {\n databases.set(dbName, new DatabaseWrapper(dbName, version));\n }\n\n return ResponseWrapper.success({ version });\n },\n\n close: async (dbName) => {\n databases.delete(dbName);\n return ResponseWrapper.success();\n },\n\n sql: async (dbName, sql, ...args) => {\n log(sql);\n\n const db = databases.get(dbName);\n if (!db) {\n throw new WebSQLAdapterError(\"Database not open\");\n }\n\n const result = await db.sql(sql, ...args);\n return ResponseWrapper.success(result);\n },\n\n delete: async (dbName) => {\n throw new WebSQLAdapterError(\"Delete not implemented\");\n },\n\n debug: enableDebug\n};\n"],"sourceRoot":""}