New webpack build
This commit is contained in:
parent
5517a0ba1d
commit
494cd97442
115
lib/pawsqlite.js
115
lib/pawsqlite.js
@ -87,6 +87,59 @@ module.exports =
|
||||
/************************************************************************/
|
||||
/******/ ({
|
||||
|
||||
/***/ "./src/adapter_wrapper.mjs":
|
||||
/*!*********************************!*\
|
||||
!*** ./src/adapter_wrapper.mjs ***!
|
||||
\*********************************/
|
||||
/*! exports provided: wrapAdapter */
|
||||
/***/ (function(__webpack_module__, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wrapAdapter", function() { return wrapAdapter; });
|
||||
/* harmony import */ var _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pawsqlite_error.mjs */ "./src/pawsqlite_error.mjs");
|
||||
|
||||
|
||||
|
||||
function wrapAdapter(adapter) {
|
||||
const wrapped = {};
|
||||
|
||||
["name", "open", "close", "delete", "sql"].forEach((prop) => {
|
||||
if (!(prop in adapter)) {
|
||||
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_0__["PawSQLiteError"](`Invalid adapter: missing property: ${ prop }`);
|
||||
}
|
||||
|
||||
if (
|
||||
prop === "name" && !(
|
||||
typeof adapter[prop] === "string" ||
|
||||
adapter[prop] instanceof String
|
||||
) ||
|
||||
prop !== "name" && (
|
||||
typeof adapter[prop] !== "function"
|
||||
)
|
||||
) {
|
||||
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_0__["PawSQLiteError"]("Invalid adapter: invalid type for property: " +
|
||||
prop);
|
||||
}
|
||||
|
||||
if (typeof adapter[prop] === "function") {
|
||||
wrapped[prop] = async (...args) => {
|
||||
try {
|
||||
return await adapter[prop](...args);
|
||||
} catch (err) {
|
||||
throw _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_0__["PawSQLiteError"].from(err);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
wrapped[prop] = adapter[prop];
|
||||
}
|
||||
});
|
||||
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./src/database.mjs":
|
||||
/*!**************************!*\
|
||||
!*** ./src/database.mjs ***!
|
||||
@ -206,8 +259,10 @@ function enableDebug(active) {
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _database_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./database.mjs */ "./src/database.mjs");
|
||||
/* harmony import */ var _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./pawsqlite_error.mjs */ "./src/pawsqlite_error.mjs");
|
||||
/* harmony import */ var _log_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./log.mjs */ "./src/log.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");
|
||||
|
||||
|
||||
|
||||
|
||||
@ -230,56 +285,26 @@ const adapters = [];
|
||||
return adapter.delete(dbName);
|
||||
},
|
||||
registerAdapter: function(adapter) {
|
||||
adapters.push(wrapAdapter(adapter));
|
||||
const wrapped = Object(_adapter_wrapper_mjs__WEBPACK_IMPORTED_MODULE_1__["wrapAdapter"])(adapter);
|
||||
|
||||
if (getAdapter(wrapped.name)) {
|
||||
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__["PawSQLiteError"](`An adapter with the name: ${ wrapped.name } ` +
|
||||
`Already exists`);
|
||||
}
|
||||
|
||||
adapters.push(wrapped);
|
||||
},
|
||||
debug: _log_mjs__WEBPACK_IMPORTED_MODULE_2__["enableDebug"],
|
||||
Error: _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__["PawSQLiteError"]
|
||||
debug: _log_mjs__WEBPACK_IMPORTED_MODULE_3__["enableDebug"],
|
||||
Error: _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__["PawSQLiteError"]
|
||||
});
|
||||
|
||||
|
||||
function wrapAdapter() {
|
||||
const wrapped = {};
|
||||
|
||||
["name", "open", "close", "delete", "sql"].forEach((prop) => {
|
||||
if (!(prop in adapter)) {
|
||||
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__["PawSQLiteError"](`Invalid adapter: missing property: ${ prop }`);
|
||||
}
|
||||
|
||||
if (
|
||||
prop === "name" && !(
|
||||
typeof adapter[prop] === "string" ||
|
||||
adapter[prop] instanceof String
|
||||
) ||
|
||||
prop !== "name" && (
|
||||
typeof adapter[prop] !== "function"
|
||||
)
|
||||
) {
|
||||
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__["PawSQLiteError"]("Invalid adapter: invalid type for property: " +
|
||||
prop);
|
||||
}
|
||||
|
||||
if (typeof adapter[prop] === "function") {
|
||||
wrapped[prop] = async (...args) => {
|
||||
try {
|
||||
return await adapter[prop](...args);
|
||||
} catch (err) {
|
||||
throw _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__["PawSQLiteError"].from(err);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
wrapped[prop] = adapter[prop];
|
||||
}
|
||||
});
|
||||
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
|
||||
function getAdapter(adapterName) {
|
||||
function getAdapter(adapterName, silent=false) {
|
||||
const adapter = adapters.find((a) => a.name === adapterName);
|
||||
|
||||
if (!adapter) {
|
||||
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_1__["PawSQLiteError"](`Unknown Adapter: ${adapterName}`);
|
||||
if (!(silent || adapter)) {
|
||||
throw new _pawsqlite_error_mjs__WEBPACK_IMPORTED_MODULE_2__["PawSQLiteError"](`Unknown Adapter: ${adapterName}`);
|
||||
}
|
||||
|
||||
return adapter;
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user