Browse Source

Converted to named export for ES6 module

master
Ben Ashton 2 years ago
parent
commit
7501617e1e
  1. 136
      cjs/pawsqlite.js
  2. 1
      cjs/pawsqlite.js.map
  3. 1
      lib/pawsqlite.js.map
  4. 4
      package.json
  5. 8
      src/pawsqlite.mjs
  6. 8
      src/pawsqlite_cjs.mjs
  7. 4
      webpack.config.js

136
lib/pawsqlite.js → cjs/pawsqlite.js

@ -164,6 +164,77 @@ function enableDebug(active) {
/***/ }),
/***/ "./src/pawsqlite.mjs":
/*!***************************!*\
!*** ./src/pawsqlite.mjs ***!
\***************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "PawSQLiteError": () => (/* reexport safe */ _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError),
/* harmony export */ "PawSQLite": () => (/* binding */ PawSQLite)
/* harmony export */ });
/* harmony import */ var _database_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./database.mjs */ "./src/database.mjs");
/* harmony import */ var _adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./adapter_wrapper.mjs */ "./src/adapter_wrapper.mjs");
/* harmony import */ var _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pawsqlite_error.mjs */ "./src/pawsqlite_error.mjs");
/* harmony import */ var _log_mjs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./log.mjs */ "./src/log.mjs");
const adapters = [];
const PawSQLite = {
open: async function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
let db = new _database_mjs__WEBPACK_IMPORTED_MODULE_0__.Database(dbName, adapter);
await db.open();
return db;
},
delete: function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
return adapter.delete(dbName);
},
registerAdapter: function(adapter) {
if (!adapter) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError("Invalid adapter");
}
const wrapped = (0,_adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__.wrapAdapter)(adapter);
if (getAdapter(wrapped.name, true)) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError(`An adapter with the name: ${ wrapped.name } ` +
`Already exists`);
}
(0,_log_mjs__WEBPACK_IMPORTED_MODULE_3__.log)(`Registered adapter: ${ wrapped.name }`);
adapters.push(wrapped);
},
debug: _log_mjs__WEBPACK_IMPORTED_MODULE_3__.enableDebug
};
function getAdapter(adapterName, silent=false) {
const adapter = adapters.find((a) => a.name === adapterName);
if (!(silent || adapter)) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError(`Unknown Adapter: ${adapterName}`);
}
return adapter;
}
/***/ }),
/***/ "./src/pawsqlite_error.mjs":
/*!*********************************!*\
!*** ./src/pawsqlite_error.mjs ***!
@ -502,70 +573,23 @@ class TransactionManager {
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
/*!***************************!*\
!*** ./src/pawsqlite.mjs ***!
\***************************/
/*!*******************************!*\
!*** ./src/pawsqlite_cjs.mjs ***!
\*******************************/
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _database_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./database.mjs */ "./src/database.mjs");
/* harmony import */ var _adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./adapter_wrapper.mjs */ "./src/adapter_wrapper.mjs");
/* harmony import */ var _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pawsqlite_error.mjs */ "./src/pawsqlite_error.mjs");
/* harmony import */ var _log_mjs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./log.mjs */ "./src/log.mjs");
const adapters = [];
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
open: async function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
let db = new _database_mjs__WEBPACK_IMPORTED_MODULE_0__.Database(dbName, adapter);
await db.open();
return db;
},
delete: function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
return adapter.delete(dbName);
},
registerAdapter: function(adapter) {
if (!adapter) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError("Invalid adapter");
}
const wrapped = (0,_adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__.wrapAdapter)(adapter);
if (getAdapter(wrapped.name, true)) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError(`An adapter with the name: ${ wrapped.name } ` +
`Already exists`);
}
(0,_log_mjs__WEBPACK_IMPORTED_MODULE_3__.log)(`Registered adapter: ${ wrapped.name }`);
adapters.push(wrapped);
},
debug: _log_mjs__WEBPACK_IMPORTED_MODULE_3__.enableDebug,
Error: _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError
});
/* harmony import */ var _pawsqlite_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pawsqlite.mjs */ "./src/pawsqlite.mjs");
/* harmony import */ var _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./pawsqlite_error.mjs */ "./src/pawsqlite_error.mjs");
function getAdapter(adapterName, silent=false) {
const adapter = adapters.find((a) => a.name === adapterName);
if (!(silent || adapter)) {
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__.PawSQLiteError(`Unknown Adapter: ${adapterName}`);
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Object.create(_pawsqlite_mjs__WEBPACK_IMPORTED_MODULE_0__.PawSQLite, {
Error: {
value: _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__.PawSQLiteError
}
return adapter;
}
}));
})();
module.exports = __webpack_exports__.default;

1
cjs/pawsqlite.js.map

File diff suppressed because one or more lines are too long

1
lib/pawsqlite.js.map

File diff suppressed because one or more lines are too long

4
package.json

@ -2,10 +2,10 @@
"name": "pawsqlite",
"version": "1.0.0",
"description": "An SQLite interface with adapters for Cordova and WebSQL",
"main": "./lib/pawsqlite.js",
"main": "./cjs/pawsqlite.js",
"exports": {
"import": "./src/pawsqlite.mjs",
"require": "./lib/pawsqlite.js"
"require": "./cjs/pawsqlite.js"
},
"module": "./src/pawsqlite.mjs",
"scripts": {

8
src/pawsqlite.mjs

@ -3,11 +3,12 @@ import { wrapAdapter } from "./adapter_wrapper.mjs";
import { PawSQLiteError } from "./pawsqlite_error.mjs";
import { enableDebug, log } from "./log.mjs";
export { PawSQLiteError } from "./pawsqlite_error.mjs";
const adapters = [];
const adapters = [];
export default {
export const PawSQLite = {
open: async function(dbName, options = {}) {
const adapter = getAdapter(options.adapter);
@ -36,8 +37,7 @@ export default {
adapters.push(wrapped);
},
debug: enableDebug,
Error: PawSQLiteError
debug: enableDebug
};

8
src/pawsqlite_cjs.mjs

@ -0,0 +1,8 @@
import { PawSQLite } from "./pawsqlite.mjs";
import { PawSQLiteError } from "./pawsqlite_error.mjs";
export default Object.create(PawSQLite, {
Error: {
value: PawSQLiteError
}
});

4
webpack.config.js

@ -4,10 +4,10 @@ var outputFile = libraryName + '.js';
var config = {
mode: 'development',
entry: __dirname + '/src/pawsqlite.mjs',
entry: __dirname + '/src/pawsqlite_cjs.mjs',
devtool: 'source-map',
output: {
path: __dirname + '/lib',
path: __dirname + '/cjs',
filename: outputFile,
libraryExport: 'default',
libraryTarget: 'commonjs2',

Loading…
Cancel
Save